【问题标题】:Getting error while creating object space using JavaSpace?使用 JavaSpace 创建对象空间时出错?
【发布时间】:2014-12-09 11:00:35
【问题描述】:

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

【问题讨论】:

  • JavaSpace是什么,贴出代码
  • space() 的返回类型是什么?你可以粘贴 space() 实现吗?
  • space() 是做什么的?
  • 你必须实现 space() 来返回 JavaSpace 或者它的任何子类型
  • space() 那是我唯一不知道的事情。它不包含任何实现

标签: java jini


【解决方案1】:

你可以这样使用它:

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

【讨论】:

  • access denied ("java.net.SocketPermission" "[0:0:0:0:0:0:0:1]:8080" "connect,resolve") 第 2 行出现错误
  • 我正在使用ServiceRegistrar sr = ll.getRegistrar(); StreamServiceRegistrar 不支持
猜你喜欢
  • 2016-04-24
  • 2011-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-25
  • 1970-01-01
  • 1970-01-01
  • 2015-01-20
相关资源
最近更新 更多