Olá pessoal! Preciso da ajuda de vocês…
Bom é o seguinte:
Pessuo uma aplicação usando JMX, funcionando bem em localhost e em um servidor de testes, porém quando mudo para o servidor de produção, dá problema. Sendo que a única diferença entre os dois servidores é a quantidade de placas de rede. Tipo, o servidor de testes tem uma placa de rede ativa, assim como meu notebook, já o servidor de produção possui 3 placas de rede ativas(10.8.0.1, 192.169.3.2, 172.16.1.2), e me retorna o seguinte erro:
ERRO:
Create an RMI connector client and connect it to the RMI connector server
Exception in thread "main" java.rmi.ConnectException: Connection refused to host: 10.8.0.1; nested exception is:
java.net.ConnectException: Connection timed out: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:110)
at javax.management.remote.rmi.RMIServerImpl_Stub.newClient(Unknown Source)
at javax.management.remote.rmi.RMIConnector.getConnection(RMIConnector.java:2327)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:279)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
at com.example.Client.main(Client.java:59)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at java.net.Socket.connect(Socket.java:475)
at java.net.Socket.<init>(Socket.java:372)
at java.net.Socket.<init>(Socket.java:186)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
... 8 more
Sendo assim estou postando os códigos de exemplo em que me baseei e me retorna o mesmo erro.
INTERFACE:
package com.example;
public interface HelloMBean {
//-----------
// operations
//-----------
public void sayHello();
public int add(int x, int y);
//-----------
// attributes
//-----------
// a read-only attribute called Name of type String
public String getName();
// a read-write attribute called CacheSize of type int
public int getCacheSize();
public void setCacheSize(int size);
}
IMPLEMENTAÇÃO DA INTERFACE:
package com.example;
import javax.management.*;
public class Hello
extends NotificationBroadcasterSupport implements HelloMBean {
public void sayHello() {
System.out.println("hello, world");
}
public int add(int x, int y) {
return x + y;
}
/* Getter for the Name attribute. The pattern shown here is frequent: the
getter returns a private field representing the attribute value. In our
case, the attribute value never changes, but for other attributes it
might change as the application runs. Consider an attribute representing
statistics such as uptime or memory usage, for example. Being read-only
just means that it can't be changed through the management interface. */
public String getName() {
return this.name;
}
/* Getter for the CacheSize attribute. The pattern shown here is
frequent: the getter returns a private field representing the
attribute value, and the setter changes that field. */
public int getCacheSize() {
return this.cacheSize;
}
/* Setter for the CacheSize attribute. To avoid problems with
stale values in multithreaded situations, it is a good idea
for setters to be synchronized. */
public synchronized void setCacheSize(int size) {
int oldSize = this.cacheSize;
this.cacheSize = size;
/* In a real application, changing the attribute would
typically have effects beyond just modifying the cacheSize
field. For example, resizing the cache might mean
discarding entries or allocating new ones. The logic for
these effects would be here. */
System.out.println("Cache size now " + this.cacheSize);
/* Construct a notification that describes the change. The
"source" of a notification is the ObjectName of the MBean
that emitted it. But an MBean can put a reference to
itself ("this") in the source, and the MBean server will
replace this with the ObjectName before sending the
notification on to its clients.
For good measure, we maintain a sequence number for each
notification emitted by this MBean.
The oldValue and newValue parameters to the constructor are
of type Object, so we are relying on Tiger's autoboxing
here. */
Notification n =
new AttributeChangeNotification(this,
sequenceNumber++,
System.currentTimeMillis(),
"CacheSize changed",
"CacheSize",
"int",
oldSize,
this.cacheSize);
/* Now send the notification using the sendNotification method
inherited from the parent class NotificationBroadcasterSupport. */
sendNotification(n);
}
@Override
public MBeanNotificationInfo[] getNotificationInfo() {
String[] types = new String[] {
AttributeChangeNotification.ATTRIBUTE_CHANGE
};
String name = AttributeChangeNotification.class.getName();
String description = "An attribute of this MBean has changed";
MBeanNotificationInfo info =
new MBeanNotificationInfo(types, name, description);
return new MBeanNotificationInfo[] {info};
}
private final String name = "Reginald";
private int cacheSize = DEFAULT_CACHE_SIZE;
private static final int DEFAULT_CACHE_SIZE = 200;
private long sequenceNumber = 1;
}
MAIN:
/*
* Main.java - main class for the Hello MBean and QueueSampler MXBean example.
* Create the Hello MBean and QueueSampler MXBean, register them in the platform
* MBean server, then wait forever (or until the program is interrupted).
*/
package com.example;
import java.lang.management.ManagementFactory;
import javax.management.MBeanServer;
import javax.management.ObjectName;
public class Main {
/* For simplicity, we declare "throws Exception".
Real programs will usually want finer-grained exception handling. */
public static void main(String[] args) throws Exception {
// Get the Platform MBean Server
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
// Construct the ObjectName for the Hello MBean we will register
ObjectName mbeanName = new ObjectName("com.example:type=Hello");
// Create the Hello World MBean
Hello mbean = new Hello();
// Register the Hello World MBean
mbs.registerMBean(mbean, mbeanName);
// Wait forever
System.out.println("Waiting for incoming requests...");
while(true){}
}
}
O servidor é startado com os seguinte argumentos:
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=72 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar TesteJmxServer.jar
CLIENTE:
/*
* Client.java - JMX client that interacts with the JMX agent. It gets
* attributes and performs operations on the Hello MBean and the QueueSampler
* MXBean example. It also listens for Hello MBean notifications.
*/
package com.example;
import java.io.IOException;
import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;
import javax.management.AttributeChangeNotification;
import javax.management.JMX;
import javax.management.MBeanServerConnection;
import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
public class Client {
/**
* Inner class that will handle the notifications.
*/
public static class ClientListener implements NotificationListener {
public void handleNotification(Notification notification,
Object handback) {
echo("\nReceived notification:");
echo("\tClassName: " + notification.getClass().getName());
echo("\tSource: " + notification.getSource());
echo("\tType: " + notification.getType());
echo("\tMessage: " + notification.getMessage());
if (notification instanceof AttributeChangeNotification) {
AttributeChangeNotification acn = (AttributeChangeNotification) notification;
echo("\tAttributeName: " + acn.getAttributeName());
echo("\tAttributeType: " + acn.getAttributeType());
echo("\tNewValue: " + acn.getNewValue());
echo("\tOldValue: " + acn.getOldValue());
}
}
}
/*
* For simplicity, we declare "throws Exception". Real programs will usually
* want finer-grained exception handling.
*/
public static void main(String[] args) throws Exception {
// Create an RMI connector client and
// connect it to the RMI connector server
//
echo("\nCreate an RMI connector client and "
+ "connect it to the RMI connector server");
JMXServiceURL url = new JMXServiceURL(
"service:jmx:rmi:///jndi/rmi://192.168.3.2:72/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
// Create listener
//
ClientListener listener = new ClientListener();
// Get an MBeanServerConnection
//
echo("\nGet an MBeanServerConnection");
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
waitForEnterPressed();
// Get domains from MBeanServer
//
echo("\nDomains:");
String domains[] = mbsc.getDomains();
Arrays.sort(domains);
for (String domain : domains) {
echo("\tDomain = " + domain);
}
waitForEnterPressed();
// Get MBeanServer's default domain
//
echo("\nMBeanServer default domain = " + mbsc.getDefaultDomain());
// Get MBean count
//
echo("\nMBean count = " + mbsc.getMBeanCount());
// Query MBean names
//
echo("\nQuery MBeanServer MBeans:");
Set<ObjectName> names = new TreeSet<ObjectName>(mbsc.queryNames(null,
null));
for (ObjectName name : names) {
echo("\tObjectName = " + name);
}
waitForEnterPressed();
// ----------------------
// Manage the Hello MBean
// ----------------------
echo("\n>>> Perform operations on Hello MBean <<<");
// Construct the ObjectName for the Hello MBean
//
ObjectName mbeanName = new ObjectName("com.example:type=Hello");
// Create a dedicated proxy for the MBean instead of
// going directly through the MBean server connection
//
HelloMBean mbeanProxy = JMX.newMBeanProxy(mbsc, mbeanName,
HelloMBean.class, true);
// Add notification listener on Hello MBean
//
echo("\nAdd notification listener...");
mbsc.addNotificationListener(mbeanName, listener, null, null);
// Get CacheSize attribute in Hello MBean
//
echo("\nCacheSize = " + mbeanProxy.getCacheSize());
// Set CacheSize attribute in Hello MBean
// Calling "reset" makes the Hello MBean emit a
// notification that will be received by the registered
// ClientListener.
//
mbeanProxy.setCacheSize(150);
// Sleep for 2 seconds to have time to receive the notification
//
echo("\nWaiting for notification...");
sleep(2000);
// Get CacheSize attribute in Hello MBean
//
echo("\nCacheSize = " + mbeanProxy.getCacheSize());
// Invoke "sayHello" in Hello MBean
//
echo("\nInvoke sayHello() in Hello MBean...");
mbeanProxy.sayHello();
// Invoke "add" in Hello MBean
//
echo("\nInvoke add(2, 3) in Hello MBean...");
echo("\nadd(2, 3) = " + mbeanProxy.add(2, 3));
waitForEnterPressed();
// ------------------------------
// Manage the QueueSampler MXBean
// ------------------------------
echo("\n>>> Perform operations on QueueSampler MXBean <<<");
// Close MBeanServer connection
//
echo("\nClose the connection to the server");
jmxc.close();
echo("\nBye! Bye!");
}
private static void echo(String msg) {
System.out.println(msg);
}
private static void sleep(int millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private static void waitForEnterPressed() {
try {
echo("\nPress <Enter> to continue...");
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Por favor se alguém pouder me ajudar será de grande ajuda, estou desesperado por essa solução. Obrigado!