이 기사에 http://java.sun.com/developer/technicalArticles/tools/JavaSpaces/은 JavaSpaces 클라이언트를 실행하는 방법에 대한 자습서입니다. Eclipse에서이 클래스들을 작성하고, Launch-All 스크립트와 Run 예제를 시작했습니다. 그것은 작동합니다. 는 그 후 나는이 실행 항아리 (JavaSpaceClient.jar)에 이러한 클래스를 내 보낸 다음 명령으로 그 항아리 시도 : 그것은 잘 작동 -jar JavaSpaceClient.jar 자바, 내가 결과를 제공합니다 이 ... 자바 스페이스 자바 스페이스 검색 발견되었습니다. 공간에 메시지 작성 중 ... 공간에서 메시지 읽기 ... 메시지 읽기 : JavaSpace가 사용 가능합니다!Jini/JavaSpaces 검색 오류
제 문제는 다른 LAN 컴퓨터에서이 jar 파일을 옮길 때 동일한 명령을 입력 할 때 오류가 있음을 보여줍니다. "... 자바 스페이스 검색"
[email protected]:~/Desktop$ java -jar JavaSpaceClient.jar
Searching for a JavaSpace...
Jul 27, 2011 11:20:54 PM net.jini.discovery.LookupDiscovery$UnicastDiscoveryTask run
INFO: exception occurred during unicast discovery to biske-Inspiron-1525:4160 with constraints InvocationConstraints[reqs: {}, prefs: {}]
java.net.UnknownHostException: biske-Inspiron-1525
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:175)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at com.sun.jini.discovery.internal.MultiIPDiscovery.getSingleResponse(MultiIPDiscovery.java:134)
at com.sun.jini.discovery.internal.MultiIPDiscovery.getResponse(MultiIPDiscovery.java:75)
at net.jini.discovery.LookupDiscovery$UnicastDiscoveryTask.run(LookupDiscovery.java:1756)
at net.jini.discovery.LookupDiscovery$DecodeAnnouncementTask.run(LookupDiscovery.java:1599)
at com.sun.jini.thread.TaskManager$TaskThread.run(TaskManager.java:331)
난 그냥 쓰고 잠시 후 이러한 오류 메시지를 출력 : 다음 오류가 발생합니다. 누군가이 오류와 관련하여 도움을 줄 수 있습니까?
편집 : 내가 인터넷에서 발견 한 LookupDiscovery 클래스를 사용하고 발견을위한 :
import java.io.IOException;
import java.rmi.RemoteException;
import net.jini.core.lookup.ServiceRegistrar;
import net.jini.core.lookup.ServiceTemplate;
import net.jini.discovery.LookupDiscovery;
import net.jini.discovery.DiscoveryListener;
import net.jini.discovery.DiscoveryEvent;
/**
A class which supports a simple JINI multicast lookup. It doesn't register
with any ServiceRegistrars it simply interrogates each one that's
discovered for a ServiceItem associated with the passed interface class.
i.e. The service needs to already have registered because we won't notice
new arrivals. [ServiceRegistrar is the interface implemented by JINI
lookup services].
@todo Be more dynamic in our lookups - see above
@author Dan Creswell ([email protected])
@version 1.00, 7/9/2003
*/
public class Lookup implements DiscoveryListener {
private ServiceTemplate theTemplate;
private LookupDiscovery theDiscoverer;
private Object theProxy;
/**
@param aServiceInterface the class of the type of service you are
looking for. Class is usually an interface class.
*/
public Lookup(Class aServiceInterface) {
Class[] myServiceTypes = new Class[] {aServiceInterface};
theTemplate = new ServiceTemplate(null, myServiceTypes, null);
}
/**
Having created a Lookup (which means it now knows what type of service
you require), invoke this method to attempt to locate a service
of that type. The result should be cast to the interface of the
service you originally specified to the constructor.
@return proxy for the service type you requested - could be an rmi
stub or an intelligent proxy.
*/
Object getService() {
synchronized(this) {
if (theDiscoverer == null) {
try {
theDiscoverer =
new LookupDiscovery(LookupDiscovery.ALL_GROUPS);
theDiscoverer.addDiscoveryListener(this);
} catch (IOException anIOE) {
System.err.println("Failed to init lookup");
anIOE.printStackTrace(System.err);
}
}
}
return waitForProxy();
}
/**
Location of a service causes the creation of some threads. Call this
method to shut those threads down either before exiting or after a
proxy has been returned from getService().
*/
void terminate() {
synchronized(this) {
if (theDiscoverer != null)
theDiscoverer.terminate();
}
}
/**
Caller of getService ends up here, blocked until we find a proxy.
@return the newly downloaded proxy
*/
private Object waitForProxy() {
synchronized(this) {
while (theProxy == null) {
try {
wait();
} catch (InterruptedException anIE) {
}
}
return theProxy;
}
}
/**
Invoked to inform a blocked client waiting in waitForProxy that
one is now available.
@param aProxy the newly downloaded proxy
*/
private void signalGotProxy(Object aProxy) {
synchronized(this) {
if (theProxy == null) {
theProxy = aProxy;
notify();
}
}
}
/**
Everytime a new ServiceRegistrar is found, we will be called back on
this interface with a reference to it. We then ask it for a service
instance of the type specified in our constructor.
*/
public void discovered(DiscoveryEvent anEvent) {
synchronized(this) {
if (theProxy != null)
return;
}
ServiceRegistrar[] myRegs = anEvent.getRegistrars();
for (int i = 0; i < myRegs.length; i++) {
ServiceRegistrar myReg = myRegs[i];
Object myProxy = null;
try {
myProxy = myReg.lookup(theTemplate);
if (myProxy != null) {
signalGotProxy(myProxy);
break;
}
} catch (RemoteException anRE) {
System.err.println("ServiceRegistrar barfed");
anRE.printStackTrace(System.err);
}
}
}
/**
When a ServiceRegistrar "disappears" due to network partition etc.
we will be advised via a call to this method - as we only care about
new ServiceRegistrars, we do nothing here.
*/
public void discarded(DiscoveryEvent anEvent) {
}
}
내 클라이언트 프로그램에 자바 스페이스 서비스 쓰기 MessageEntry를 검색 할 수 단순히 시도하고 메시지를 밖으로 인쇄를 검색합니다.
import net.jini.core.entry.*;
public class MessageEntry implements Entry {
public String content;
public MessageEntry() {
}
public MessageEntry(String content) {
this.content = content;
}
public String toString() {
return "MessageContent: " + content;
}
}
EDIT2 :
import net.jini.space.JavaSpace;
public class SpaceClient {
public static void main(String argv[]) {
try {
MessageEntry msg = new MessageEntry();
msg.content = "Hello JavaSpaces wordls!";
System.out.println("Searching for JavaSpaces...");
Lookup finder = new Lookup(JavaSpace.class);
JavaSpace space = (JavaSpace) finder.getService();
System.out.println("JavaSpaces discovered.");
System.out.println("Writing into JavaSpaces...");
space.write(msg, null, 60*60*1000);
MessageEntry template = new MessageEntry();
System.out.println("Reading message from JavaSpaces...");
MessageEntry result = (MessageEntry) space.read(template, null, Long.MAX_VALUE);
System.out.println("Message: "+result.content);
} catch(Exception e) {
e.printStackTrace();
}
}
}
물론이의
이 MessageEntry 클래스입니다 : 여기에 클라이언트 프로그램입니다 나는 두 개의 Windows 컴퓨터에서 발견했다. 그 후 나는 Windows - Ubuntu combiant를 시도했지만 작동하지 않습니다. 네트워크 문제가있을 수 있습니까? 내가 서로 핑 할 때 모든 것이 괜찮습니다. Ubuntu에 DNS 문제가있을 수 있습니다.EDIT3 : Windows - JavaSpaces 서비스가 Windows에서 시작되고 클라이언트 프로그램이 Ubuntu에있는 경우 우분투 조합이 작동합니다. 역순으로하려고하면 JavaSpaces 서비스를 우분투에서 실행하고 Windows에서 클라이언트를 실행하면 오류가 발생합니다. 우분투에는 분명히 문제가 있습니다. 우분투에는 기본적으로 OpenJDK가 설치되어 있습니다. Oracle JDK를 설치하고 JAVA_HOME을 설정하고 JAVA_HOME/bin을 PATH 변수에 넣습니다. 다른 버전의 Java에 문제가있을 수 있습니다. 아마도 올바른 버전을 사용하고 있지 않을 수도 있습니다.
JavaSpaces를 도와 줄 사람이별로 없기 때문에 도와 주셔서 감사합니다. 내 질문을 편집했는데, 무엇을 바꾸라고 제안 할 수 있니? –
예제 코드로 나의 응답을 업데이트했습니다. –
사용중인 검색 코드를 보았습니다. 멀티 캐스트 검색을 사용하고있는 것처럼 보이지만 호스트를 찾을 때 문제가 발생합니다. @ beny23이 말한 것을 시도해보십시오. 또한 일종의 DNS 문제가 없는지 확인하기 위해 호스트 이름 대신 컴퓨터의 IP 주소로 유니 캐스트 검색을 지정하십시오. –