0

I am using example from this wikipedia Article http://en.wikipedia.org/wiki/Tuple_space#JavaSpaces

import java.lang.*;
import java.rmi.RMISecurityManager;
import net.jini.core.discovery.LookupLocator;
import net.jini.core.entry.Entry;
import net.jini.core.lookup.*;
import net.jini.core.lookup.ServiceRegistrar;
import net.jini.core.lookup.ServiceTemplate;
import net.jini.lookup.entry.Name;
import net.jini.space.JavaSpace;
/**
*
* @author admin
 */
public class findSpace {
  LotEntry entry = new LotEntry();            // Create the Entry object
  JavaSpace space = (JavaSpace)space();       // Create an Object Space
}

Error in Creating an object space line: space()

cannot find Symbol error

JavsSpace Code:

package net.jini.space;

import java.rmi.MarshalledObject;
import java.rmi.RemoteException;
import net.jini.core.entry.Entry;
import net.jini.core.entry.UnusableEntryException;
import net.jini.core.event.EventRegistration;
import net.jini.core.event.RemoteEventListener;
import net.jini.core.lease.Lease;
import net.jini.core.transaction.Transaction;
import net.jini.core.transaction.TransactionException;

public interface JavaSpace {

public static final long NO_WAIT = 0L;

public Lease write(Entry entry, Transaction t, long l) throws TransactionException, RemoteException;

public Entry read(Entry entry, Transaction t, long l) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException;

public Entry readIfExists(Entry entry, Transaction t, long l) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException;

public Entry take(Entry entry, Transaction t, long l) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException;

public Entry takeIfExists(Entry entry, Transaction t, long l) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException;

public EventRegistration notify(Entry entry, Transaction t, RemoteEventListener rl, long l, MarshalledObject mo) throws TransactionException, RemoteException;

public Entry snapshot(Entry entry) throws RemoteException;
}
  • What is `JavaSpace`, post the code for it – Ankur Singhal Dec 09 '14 at 11:03
  • What is the return type of space()? Can you paste the space() implementation? – SSC Dec 09 '14 at 11:04
  • What does `space()` do ? – luuksen Dec 09 '14 at 11:04
  • You will have to implement space() which returns JavaSpace or any of it's sub type – SSC Dec 09 '14 at 11:34
  • **space()** Thats the only thing i dont know about. it is not containing any implementation –  Dec 09 '14 at 11:35
  • So, you will have to provide implementation for space(). Compiler can't just substitute it for you. – SSC Dec 09 '14 at 11:35
  • @Mr.777 Sir i am using Apache River, and i don't know how to implement JavaSpace in it , i am running some examples from Internet but it is not helping me.... Some complete examples of implemented JavaSpace will be helpful for me... –  Dec 09 '14 at 11:41
  • I am using this Wikipedia Article as example [http://en.wikipedia.org/wiki/Tuple_space#JavaSpaces] –  Dec 09 '14 at 11:45
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/66469/discussion-between-mr-777-and-alinaa). – SSC Dec 09 '14 at 11:46
  • I have answered your question in chatroom – SSC Dec 09 '14 at 11:49
  • @Alinaa i hope issue is resolved now as per comments – Ankur Singhal Dec 09 '14 at 15:37

1 Answers1

0

You can use it like this:

LookupLocator ll = new LookupLocator("jini://localhost:4160");
StreamServiceRegistrar sr = ll.getStreamRegistrar();
ServiceTemplate srTemplate = new ServiceTemplate(null, new Class[] { ServiceRegistrar.class }, null);
ServiceMatches sms = sr.lookup(template, 10);
if(0 < sms.items.length) {
     JavaSpace space = (JavaSpace) sms.items[0].service;
     // do something with the space
} else {
     System.out.println("No Java Space found.");
}

But the service should be running on port 4160. If it's running on some other port, you need to specify that port number.

Also, you can read more about this here

SSC
  • 2,956
  • 3
  • 27
  • 43
  • `access denied ("java.net.SocketPermission" "[0:0:0:0:0:0:0:1]:8080" "connect,resolve")` Getting Error on Line 2 –  Dec 11 '14 at 14:05
  • I am Using `ServiceRegistrar sr = ll.getRegistrar();` **StreamServiceRegistrar** is not spported –  Dec 11 '14 at 14:06