使用JavaSpace创建对象空间时出错?

时间:2014-12-09 11:00:36

标签: java jini

我正在使用此维基百科文章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
}

创建对象空间行时出错:space()

无法找到符号错误

JavsSpace代码:

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;
}

1 个答案:

答案 0 :(得分:0)

你可以像这样使用它:

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.");
}

但是服务应该在端口4160上运行。如果它在某个其他端口上运行,则需要指定该端口号。

此外,您可以阅读有关此here

的更多信息