I have an issue with JGroups where after building my project, running it produces this error:
Caused by: java.lang.ClassNotFoundException: org.jgroups.ReceiverAdapter
My class looks something like this -
import org.jgroups.ReceiverAdapter;
import org.jgroups.Channel;
import org.jgroups.JChannel;
public class MyClass extends ReceiverAdapter implements MyInterface {
Channel channel;
String state = "state";
public MyClass() {
super();
start();
}
public void start() {
try {
channel = new JChannel();
channel.setReceiver(this);
channel.connect("ServerCluster");
channel.getState(null, 0);
System.out.println("Connected to cluster");
} catch (Exception e) {
System.out.println("Failed to connect to cluster");
}
}
public void getState(OutputStream output) throws Exception {
System.out.println("get response");
}
public void setState(InputStream input) throws Exception {
System.out.println("set test");
}
}
Running the project from IntelliJ produces no errors, but does not produce the desired prints from getState() and setState() either. I tried creating a brand new project in the Eclipse IDE, but the same is happening there too. Connecting has been working fine, states is a new addition to my project.
Running java MyClass from the command line fires the error seen at the start of this question. The JGroups jar seems to be added to the classpath properly as org.jgroups.Channel and org.jgroups.Channel (among others) are being found.
There is a SimpleChat program provided by the JGroup devs, but when I created a new project for this I encountered the same problem.
Edit
So it turns out I have to explicitly set the classpath when running from the CLI. But still, when running the code it seems like the getState() and setState() methods are never called as there are no print statements. SimpleChat doesn't print received state... like it is meant to.
Does anyone have a solution?
Best.
So, I on the JChannel I was using RpcDispatcher and it seems I can't use the dispatcher and the getState() and setState() methods on the same channel. Simple solution: create a second channel. Seems my knowledge on the fundamentals of JGroups is lacking!
Related
I am creating custom language plugin for IntelliJ
I have EOCompletionContributor class but it doesn't suggest completion words.
I expected to see "Hello" in completion's window while typing.
I added printing in the body (2 times) so I know all code is reachable.
One more detail: when my plugin starts I see error java.lang.UnsatisfiedLinkError: Unable to load library 'CoreFoundation'
After researching I found out that this error appears on mac os (I execute code on mac os too)
What does this error mean and is it connected with completion's problems?
Here is my code:
public class EOCompletionContributor extends CompletionContributor {
public EOCompletionContributor() {
System.out.println("FLAG 1\n"); // reachable
extend(CompletionType.BASIC, PlatformPatterns.psiElement(),
new CompletionProvider<CompletionParameters>() {
#Override
public void addCompletions(#NotNull CompletionParameters parameters,
#NotNull ProcessingContext context,
#NotNull CompletionResultSet resultSet) {
resultSet.addElement(LookupElementBuilder.create("Hello"));
System.out.println("FLAG 2\n"); // reachable
}
}
);
}
}
While performing a client-server communication with various forums, I am unable to perform Remote-object's lookup on the client machine.
The errors which I receive are ConnectIOException(NoRouteToHostException), and sometimes ConnectException and sometimes someother.
This is not what I want to ask. But, the main concern is how should I setup client platform and server platform --- talking about networking details --- this is what I doubt interferes with my connection.
My questions :-
How should I edit my /etc/hosts file on both client-side and server-side? Server's IP- 192.168.1.8 & Client's IP-192.168.1.100. Means, should I add the system name in both the files:
192.168.1.8 SERVER-1 # on the server side
192.168.1.100 CLIENT-1 # on the client side
Should I edit like this? Can this be one of the possible concerns? I just want to remove any doubts left over to perform the rmi-communication!
Also, I am also setting Server's hostname property using System.setProperty("java.rmi.server.hostname",192.168.1.8); on the server side. Should I do the same on the client-side too?
I've read about setting classpath while running the java program on both server-side as well as the client-side. I did this too,but,again the same exceptions. No difference at all. I've read that since Java update 6u45, classpaths aren't necessary to include! Please throw some light on this too...
If I am missing something, Please enlighten about the same too. A brief idea/link to resources are most preferred.
You don't need any of this unless you have a problem. The most usual problem is the one described in the RMI FAQ #A.1, and editing the hosts file of the server or setting java.rmi.server.hostname in the server JVM is the solution to that.
'No route to host' is a network connectivity problem, not an RMI problem, and not one you'll solve with code or system property settings.
Setting the classpath has nothing to do with network problems.
Here is server example of which transfers an concrete class. This class must be exist in server and client classpath with same structure
Message:
public class MyMessage implements Serializable {
private static final long serialVersionUID = -696658756914311143L;
public String Title;
public String Body;
public MyMessage(String strTitle) {
Title = strTitle;
Body = "";
}
public MyMessage() {
Title = "";
Body = "";
}
}
And here is the server code that gets an message and returns another message:
public class SimpleServer {
public String ServerName;
ServerRemoteObject mRemoteObject;
public SimpleServer(String pServerName) {
ServerName = pServerName;
}
public void bindYourself() {
try {
mRemoteObject = new ServerRemoteObject(this);
java.rmi.registry.Registry iRegistry = LocateRegistry.getRegistry(RegistryContstants.RMIPort);
iRegistry.rebind(RegistryContstants.CMName, mRemoteObject);
} catch (Exception e) {
e.printStackTrace();
mRemoteObject = null;
}
}
public MyMessage handleEvent(MyMessage mMessage) {
MyMessage iMessage = new MyMessage();
iMessage.Body = "Response body";
iMessage.Title = "Response title";
return iMessage;
}
public static void main(String[] server) {
SimpleServer iServer = new SimpleServer("SERVER1");
iServer.bindYourself();
while (true) {
try {
Thread.sleep(10000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
and here is the remote interface of server remote object:
public interface ISimpleServer extends java.rmi.Remote{
public MyMessage doaction(MyMessage message) throws java.rmi.RemoteException;
}
all you need is adding MyMessage class both in server and client classpath.
I have been trying to get a Windows service running from my JAR file. WinRun4j seems to be able to do the job, but I can't get it to work. I am especially finding it quite difficult to debug. I tried several methods for logging (writing to a .txt file, WinRun4j's EventLog class) but I can't seem to generate any output.
The service installs fine (eventually..) and I can start it. It should start a Jetty server that generates an XML file that can be reached over HTTP. The app works for a stand-alone version, just not for the service. The service is started, but as soon as I call the URL it stops without generating an error.
This is my Service class:
package com.some.package;
import org.boris.winrun4j.AbstractService;
import org.boris.winrun4j.ServiceException;
/**
* A basic service.
*/
public class StockService extends AbstractService {
private StockServer srv;
public int serviceMain(String[] args) throws ServiceException {
while (!shutdown) {
try {
Thread.sleep(5000);
} catch(InterruptedException e) {
}
if(srv == null) {
try {
srv = new StockServer();
srv.start();
} catch (Exception e) {
}
}
}
return 0;
}
}
I found out that the service didn't want to start if I started the Jetty server from the serviceMain class. I had to start a new thread. So StockServer extends Thread:
public class StockServer extends Thread {
private Server server;
public void run() {
if (server == null) {
try {
server = new Server(8080);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/example");
StockServlet stockServlet = new StockServlet();
context.addServlet(new ServletHolder(stockServlet), "/stock/*");
server.setHandler(context);
server.setStopAtShutdown(true);
server.start();
server.join();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
}
Since it runs perfectly fine as Java application I just don't know how to get this thing debugged. I hope one of you can point me in the right direction :).
I ended up using the Java Service Wrapper (JSW). This seemed a lot more complex but ended up to be quite easy. It also provides logging by default so I could easily fix the errors. The JSW had problems finding the correct JDK, since JSW is 32bit and I installed JDK1.7 64 bit (and 1.6 32bit). Installing JDK1.7 32bit fixed it. That might have been the problem with WinRun4j as well, but that is something I will never know :).
i'm writing a bit of code and i keep getting this error, it's to do with where i call network.addstation
here's the code, there are other methods in the network method but i thought i'd just show one, but it appears when you call any method. any help would be much appreaciated. thanks.
public class MyNetworkReader implements NetworkReader {
Network network = null;
#Override
public Network read(InputStream stream) {
Scanner scan = null;
scan = new Scanner(stream);
while (scan.hasNext()) {
String fromStation = scan.next();
if (!fromStation.equalsIgnoreCase("connection:")) ;
network.addStation(fromStation)
System.out.println(fromStation);
}
}
return network;
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
public class MyNetwork implements Network {
HashMap<String, ArrayList> stations = new HashMap<String, ArrayList>();
public void addStation(String station) {
stations.put(station, null);
}
}
Are you constructing a MyNetwork instance anywhere?
Seems like you want
Network network = null;
To be
MyNetwork network = new MyNetwork();
Because you're trying to call a method on an uninitiated object. But your MyNetwork class needs a constructor.
Note you can also get this error immediately upon running C++ code, with the default NetBeans setup, if your Project's Properties->Run->Console Type is set to Internal Terminal and not External Terminal; at least when using FLTK graphics on Ubuntu. In this case it's a NetBeans internal handshaking problem and not a source code problem.
You're yourself initializing network to null, in second line of your code, then it will obviously throw NullPointerException
As DragonLord said, it is not a source code issue. You will be able to tell because that should happen whenever you run any C++ code. I had the same problem. I did something slightly different than DragonLord, though. I set the output of the program to Project Properties>Run>Console Type and set it to Standard Output.
i have written small RMI chat program and its compiling properly.but when i try to run Client program it results exception "java.rmi.NotBoundException - ServerInterface"
Server program runs without any errors..please help me to solve this.
here is some of Client code
public static void main (String[] args)
{
String address = "rmi://localhost/ServerInterface";
try
{
ServerInterface si= (ServerInterface) Naming.lookup(address);
new Thread(new Client(si)).start();
}
catch (Exception e)
{
System.err.println(e.toString()) ;
}
}
It looks like you are attempting to look up a name that is not bound.
public class NotBoundException extends Exception
A NotBoundException
is thrown if an attempt is made to lookup or unbind in the registry a
name that has no associated binding.
A NotBoundException is thrown if an attempt is made to lookup or unbind in the registry a name that has no associated binding.
What is your server code look like? This exception you are having most likely caused by server not set up properly.
I think in your server code you are bind with name ChatServer
Naming.rebind("ChatServer", new Server());
But in your client code you are using ServerInterface name
String address = "rmi://localhost/ServerInterface";
For more details Naming
Just make sure your registry.rebind(ClassName.class.getSimpleName(), new ClassImplementaion()) is match to your ClassImplementation.