Erlang Jinterface node nameserver problems on windows - server

I am trying to implement an interface for my erlang program using jinterface. When I call the command OtpNode otpNode = new OtpNode(nodeName, cookie); java throws an IOException with
java.io.IOException: Nameserver not responding on DESKTOP-GIR29G3 when publishing javanode.
It doesn't seem to be common problem for people as I couldn't find anything similar online. It's a local node with the node name being "javanode" with no fullstops or dashes. Why would there be a DNS issue on a local node?
I have tried starting an erlang node in the directory the java program is started as well as starting the erlang console on my pc, but I'm very new to erlang so those were just wild guesses that some erlang VM must be running.
Here is the code that may help:
public Erlterface()
{
Thread t = new Thread(new Runnable() {
public void run() {
setupMBox();
}
});
t.start();
}
private void setupMBox()
{
try {
String nodeName = "javanode";
String cookie = "jinterface";
//String[] names = OtpEpmd.lookupNames();
OtpNode otpNode = new OtpNode(nodeName, cookie); //CRASH HAPPENS HERE
OtpMbox Mbox = otpNode.createMbox("javaserver");
The error from the console:
Connected to the target VM, address: '127.0.0.1:54025', transport: 'socket'
java.io.IOException: Nameserver not responding on DESKTOP-GIR29G3 when publishing javanode
at com.stellar.base.schedule.com.ericsson.otp.erlang.OtpEpmd.r4_publish(OtpEpmd.java:344)
at com.stellar.base.schedule.com.ericsson.otp.erlang.OtpEpmd.publishPort(OtpEpmd.java:141)
at com.stellar.base.schedule.com.ericsson.otp.erlang.OtpNode$Acceptor.publishPort(OtpNode.java:784)
at com.stellar.base.schedule.com.ericsson.otp.erlang.OtpNode$Acceptor.<init>(OtpNode.java:776)
at com.stellar.base.schedule.com.ericsson.otp.erlang.OtpNode.init(OtpNode.java:232)
at com.stellar.base.schedule.com.ericsson.otp.erlang.OtpNode.<init>(OtpNode.java:196)
at com.stellar.base.schedule.com.ericsson.otp.erlang.OtpNode.<init>(OtpNode.java:149)
at com.stellar.base.schedule.Erlterface.setupMBox(Erlterface.java:40)
at com.stellar.base.schedule.Erlterface.access$000(Erlterface.java:16)
at com.stellar.base.schedule.Erlterface$1.run(Erlterface.java:26)
at java.lang.Thread.run(Thread.java:745)
Thanks in advance
Dale
UPDATE ADDITIONAL INFORMATION:
I went into a dive to try and figure out where exactly the train leaves the rails but I'm taking wild guesses as to what I should flag as potential issues. I just want to add some additional information here to help:
In OptEpmd the following is caught before the io exception is thrown
java.net.ConnectException: Connection refused: connect
The final source is the native DeulSocketImpl class that I suppose calls on windows to do the final connection thingamabob ad it fails:
static native int connect0(int var0, InetAddress var1, int var2) throws IOException;
Am I missing something in setting up the erlang node? I surely don't have to start it manually? I've diabled my firewall completely to test it. How do I figure out why the connection was refused?

Related

MongoDB connection refused to local node when connecting to replica set

I have a replica set consisting of four nodes (ux002, ux009, ux019, ux020). I have a program that I'd like to run in parallel on each of the same four nodes which connects to this replica set using the Mongo Java driver.
Examining the status of the replica set shows that all four nodes are operating fine, however the program throws the following warning message on all four nodes:
Nov 12, 2014 2:34:40 PM com.mongodb.ConnectionStatus$UpdatableNode update
WARNING: Server seen down: ux009/127.0.1.1:27017 - java.io.IOException - message: couldn't connect to [ux009/127.0.1.1:27017] bc:java.net.ConnectException: Connection refused
However, on each node, the server which is seen down is the one the program is running on. I.e. I run the program on ux009, and it tells me ux009 is down. I run it on ux002, it tells me ux002 is down.
I made a stupidly simple program to test whether there was something wrong with my original code, but the same warning persists:
public static void main(String[] args) throws Exception {
List<ServerAddress> addrs = new ArrayList<>();
if (args.length == 0) {
addrs.add(new ServerAddress("localhost", 27017));
} else {
for (String a : args) {
String[] host = a.split(":");
addrs.add(new ServerAddress(host[0], Integer.valueOf(host[1])));
}
}
mongo = new Mongo(addrs);
Thread.sleep(5000); // Sleep to give it time to print messages
mongo.close();
}
And I run it as follows:
java -jar mongo-test.jar ux002:27017 ux009:27017 ux019:27017 ux020:27017
Could it be that mongod isn't configured correctly? Or perhaps I am misusing the Java API?
The Mongo Java driver is version 2.9.3, and mongod is version 2.6.5.
Many thanks in advance!
-Jim
The IP is a little strange for the local host:
ux009/127.0.1.1:27017
I would have expected that to be:
ux009/127.0.0.1:27017
Most likely someone fat fingered the ip address in the /etc/hosts on each machine.
Posting the answer here for completeness. The issue was that the bind_ip parameter in the mongod configuration file had been set to the IP address of only one of the nodes. Thanks to helmy for spotting that.

How to start rmic registry and server using java 1.7?

I am new to java RMI, actually I wrote, compiled and started rmic, and also tried to start server but failed due to _stub 'ClassNotFound' exception..... I'm using java 7... I searched a lot on Google but nobody told step by step example that could work...I got some idea about stteing codebase and security policy but not very clear suggestion that how to do it.. please help telling me steps including command-line .......... please... I have everything just tell me how to start server, and required settings like codebase or policy settings etc... Thanks
You don't need to use rmic. Instead, create your server object and call one of the exportObject() method overloads that has the port parameter. For example,
MyRemoteIntf stub = UnicastRemoteObject.exportObject(server, 0);
This will cause RMI to generate the stub automatically. (The documentation is horribly unclear on this point. If you use the version without the port parameter, it will use only the old, rmic-generated stubs instead of generating them automatically.)
Also, make sure that your remote interface is in the codebase of both the registry and any clients. You'll get different errors if you haven't done this properly. This has been answered a bunch of times on Stackoverflow already; search for "rmi ClassNotFoundException".
There is no need to use the rmic command since java (J2SE) 5.0 the stubs are dynamically generated at runtime.
Here is a basic step by step example of how to use RMI.
First define the Remote interface that defines what the client can see and do:
public interface FooService extends Remote {
// Don't forget to add throws RemoteException.
public void bar() throws RemoteException;
}
NOTE: if you do not add throws RemoteException to the method declaration you will encounter the following exception:
java.lang.IllegalArgumentException: illegal remote method encountered: public abstract void RMIExample.FooService.bar()
After you defined what the client can do you must define the concrete implementation of the methods on the server slide:
public class FooServiceImpl extends UnicastRemoteObject implements FooService {
public FooServiceImpl() throws RemoteException {
super();
}
public void bar() {
System.out.println("I was remotely invoked!");
}
}
The implementation class must inherit from UnicastRemoteObject and implement the Remote interface you defined earlier and the class must have a constructor that throws RemoteException.
Now that you have fully defined the remote functionality you must bind the implementation object to a URL on the server side:
// 4000 is the port to listen on.
LocateRegistry.createRegistry(4000);
Naming.rebind("//127.0.0.1:4000/foobar", new FooServiceImpl());
Now that you have your server up and running you need a stub instance A.K.A a proxy in the client side:
FooService fooService =
(FooService)Naming.lookup("//127.0.0.1:4000/foobar");
and finally invoke the remote method:
fooService.bar();
the following should be printed on the server side:
I was remotely invoked!
References:
http://en.wikipedia.org/wiki/Java_remote_method_invocation
http://docs.oracle.com/javase/1.5.0/docs/guide/rmi/relnotes.html

Netbeans Run->Stop Build does not stop the running java processes

I'm using Netbeans 7.1.2 on Mac OS X Lion 10.7.3.
I have a simple java server (using netty) project and after I build and run the project then try to stop the running by Run->Stop Build it does not terminate the java server process.
For example, my server app uses port 8080 and even after I stop running from the netbeans the port 8080 is in use and the app keeps running. I have to manually kill the java process from activity monitor.
What's the correct procedure to end the running app started by Netbeans?
Greatly appreciate your help. Thanks in advanced.
Have a look at the documentation: http://netty.io/docs/stable/guide/html/. Scroll down to section 9. Shutting Down Your Application.
Your main app ahs to look something like:
package org.jboss.netty.example.time;
public class TimeServer {
static final ChannelGroup allChannels = new DefaultChannelGroup("time-server"(35));
public static void main(String[] args) throws Exception {
...
ChannelFactory factory = ...;
ServerBootstrap bootstrap = ...;
...
Channel channel = bootstrap.bind(...);
allChannels.add(channel);
...
// Shutdown code
ChannelGroupFuture future = allChannels.close();
future.awaitUninterruptibly();
factory.releaseExternalResources();
}
}
You handler needs:
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) {
TimeServer.allChannels.add(e.getChannel());
}
You have to:
1. Store all your channels in a ChannelGroup
2. When shutting down, close all channel and release resources.
Hope this helps.

EF4 EntityException - The underlying provider failed on Open

Okay, this is a new one. I'm trying to debug my project, which I've done many times in the past, and I'm now getting this exception in one of my repositories. I haven't seen it before now. I haven't touched my repos in days, and my connection string is the same as its always been. The inner exception states:
{"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"}
And the code it's choking on is:
public class HGArticleRepository : IArticleRepository
{
private HGEntities _siteDB = new HGEntities();
public List<Article> Articles
{
get { return _siteDB.Articles.ToList(); } // <-- this is the line
}
// more repo code
}
Again, like I said, I've never encountered this exception before, and I haven't touched my domain code in days.
This error usually means:
Connection String points to nonexistent SQL Server.
Connection String points to SQL Server that was shut down. Or not started.
Named pipes transport was disabled in SQL Server settings.
Check them carefully one by one. In your case I guess it is 2.
A second option of solution:
Review that IIS is running.
In my case it was stopped, so I got the same error.

RMI Binding Issue (from Windows RMI Server to Ubuntu RMI Registry)

I have an RMI Server which correctly binds to an RMI Registry when running on localhost (to demonstrate that things are setup correctly). The code which does this is:
private void exposeTickHistoryRemoteProvider(TickHistoryRemoteInterface aTickHistoryServer) {
if (System.getSecurityManager() == null) {
SecurityManager mySecurityManager = getSecurityManager();
System.setSecurityManager(mySecurityManager);
}
String rmiServerHostname = System.getProperties().getProperty("java.rmi.server.hostname");
try {
TickHistoryRemoteInterface stub =
(TickHistoryRemoteInterface) UnicastRemoteObject.exportObject(aTickHistoryServer, 0);
Registry registry = LocateRegistry.getRegistry(rmiServerHostname);
String[] services = registry.list();
registry.rebind(RMI_SERVICENAME_REUTERS_TICKHISTORY_SERVER, stub);
log.info(RMI_SERVICENAME_REUTERS_TICKHISTORY_SERVER + " bound");
} catch (Exception e) {
log.error(RMI_SERVICENAME_REUTERS_TICKHISTORY_SERVER + " exception:" + e.toString());
e.printStackTrace();
}
}
My localhost is running Windows with the following version of Java:
C:\eclipse>java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode)
Now, my issue is that I want to bind to an RMIRegistry running on a different machine (running Ubuntu 10.04, with OpenJDK IcedTea6 1.8.1, java version 1.6.0_18).
On this Ubuntu machine, I have nothing in my CLASSPATH (echo $CLASSPATH), and am running the OpenJDK RMIRegistry (as opposed to the one bundled with Ubuntu):
sudo /usr/lib/jvm/java-6-openjdk/jre/bin/rmiregistry &
Now, in the code above, when variable rmiServerHostname is "localhost" with the RMIRegistry running on my Windows localhost, the code works correctly (the RMI Server code binds to the RMI Registry). However, when rmiServerHostname is my remote Ubuntu machine ("deity") I get the following exception thrown on the "rebind" invocation:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: com.relative.tickhistory.provider.TickHistoryRemoteInterface
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: com.relative.tickhistory.provider.TickHistoryRemoteInterface
If I kill the RMIRegistry, I get a different error message (I would expect):
java.rmi.ConnectException: Connection refused to host: deity; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.list(Unknown Source)
I would assume there is no incompatibility between these implementations of RMIRegistry (Windows Java6 and Ubuntu OpenJDK 6)... but, I am unsure how to get to the bottom of this one. Especially because I know the code works correctly (in the first, Windows/localhost) example.
Progress So Far
Thanks alot for the helpful responses. I understand that I was getting confused between the rmiServerHostname (running on my localhost), and the rmiRegistryHostname (running on 'deity'). I have revised the code, with the following, but am still getting the same problem (note the change in the line "Registry registry = LocateRegistry.getRegistry(rmiRegistryHostname)"):
String rmiServerCodebase = System.getProperties().getProperty("java.rmi.server.codebase");
String rmiServerHostname = System.getProperties().getProperty("java.rmi.server.hostname");
String rmiRegistryHostname = "deity";
System.out.println("rmiServerCodebase=" + rmiServerCodebase + "; rmiServerHostname=" + rmiServerHostname);
try {
TickHistoryRemoteInterface stub =
(TickHistoryRemoteInterface) UnicastRemoteObject.exportObject(aTickHistoryServer, 0);
Registry registry = LocateRegistry.getRegistry(rmiRegistryHostname);
The output of the print statement is (note, my localhost is 'RTPC-16')
"rmiServerCodebase=file:///C:/workspace/DEV/ReutersTickHistoryServer/ReutersTickHistoryInterface.jar; rmiServerHostname=RTPC-16"
This file does exist:
C:\>dir c:\workspace\DEV\ReutersTickHistoryServer\ReutersTickHistoryInterface.jar
Volume in drive C is OS
Volume Serial Number is 7AEB-A105
Directory of c:\workspace\DEV\ReutersTickHistoryServer
22/10/2010 12:21 PM 9,467 ReutersTickHistoryInterface.jar
1 File(s) 9,467 bytes
So, to summarise once more:
This code works when RMIRegistry and RMIServer are on same physical host (eg, localhost)
The problem occurs when I try to run only the RMIRegistry process on a separate host (ie, RMIRegistry is running on 'deity' as I want it to be whilst RMIServer is running on my localhost 'RTPC-16')
I was bundling the RMI interface codebase ("ReutersTickHistoryInterface.jar") on both the client and server, so I was not anticipating RMI would need to transport any class definitions - RMI simply create the stub classes on the client and handle the actual RMI calls
Also you are misusing java.rmi.server.hostname. That's not what it is for. As this code is binding to the Registry, and as you can only do that if the Registry is running in the same host, you should just use "localhost" when obtaining the registry reference for binding or unbinding.
You are getting this exception because the rmiregistry can't locate the remote object's stubs or other classes needed by the stub. You need to specify the java.rmi.server.codebase property when starting the server, set to be the location of the implementation stubs. This is required so that the stub class can be dynamically downloaded to the registry.
For more details on this property take a look at the Dynamic code downloading using RMI tutorial.