Catalin Merfu

Ranch Hand
+ Follow
since May 26, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Catalin Merfu

JNetStart facilitates launching Java Swing applications deployed on a remote server without installing or downloading the application component files. The technology narrows the gap between the web browser and Swing by making large client applications instantly available to the user and providing a web style experience in the startup process.

http://www.accendia.com
18 years ago
Thanks Henry,

The listener should be automatically added when JConsole connects to the mbean server?

Would you be able to post a bean that doesn't export methods but is just used for posting notification?
19 years ago
Thanks,

I'm building an appender for log4j that send the log events to JConsole.
Do you know what's wrong here, I'm not receiving any notifications:


import javax.management.MBeanNotificationInfo;
import javax.management.Notification;
import org.apache.log4j.spi.LoggingEvent;
import javax.management.NotificationBroadcasterSupport;
import org.apache.log4j.Appender;
import org.apache.log4j.spi.ErrorHandler;
import org.apache.log4j.Layout;
import org.apache.log4j.spi.Filter;

public class JMXLogAppender extends NotificationBroadcasterSupport implements JMXLogAppenderMBean, Appender
{
static private final String LOG_EVENT_TYPE = "LOG_EVENT";
static private final String LOG_MBEAN_DESCR = "LogAppender MBean";

private String appenderName_;
private Layout layout_;

private long sequence_ = 0;

public JMXLogAppender()
{
}

public MBeanNotificationInfo[] getNotificationInfo()
{
String[] types = new String[] { LOG_EVENT_TYPE };
String name = Notification.class.getName();

MBeanNotificationInfo info = new MBeanNotificationInfo( types, name, LOG_MBEAN_DESCR );

return new MBeanNotificationInfo[] { info };
}

public int getValue()
{
return 0;
}

public void setName( String name )
{
appenderName_ = name;
}

public String getName()
{
return appenderName_;
}

public void addFilter(Filter filter)
{
return;
}

public Filter getFilter()
{
return null;
}

public void clearFilters()
{
}

public void setErrorHandler( ErrorHandler errorHandler )
{
}

public ErrorHandler getErrorHandler()
{
return null;
}

public void setLayout(Layout layout)
{
layout_ = layout;
}

public Layout getLayout()
{
return layout_;
}

public void doAppend( LoggingEvent event )
{
synchronized(this)
{
sequence_++ ;
}

String message = event.getRenderedMessage();

Notification notif = new Notification( LOG_EVENT_TYPE, this, sequence_ );// , event.timeStamp, message );
sendNotification( notif );
}

public boolean requiresLayout()
{
return true;
}

public void close()
{
}
}
19 years ago
NotificationBroadcasterSupport.sendNotification( notif ) works only when called from inside the MBean method invocation (JMX thread) and does nothing when called from an user thread.

I want to spawn a thread inside an MBean method call, perform a lengthy op and send a notif when it's done.

Any thoughts?
19 years ago
Use a comm framework that is using non-blocking sockets: http://www.accendia.com
Michael,

Does the server need to open another socket to connect back to the client?
Are there at least 2 sockets involved in the RMI session?
19 years ago
If you installed the JDK look at this Swing demo application:

JAVA_HOME\demo\jfc\SwingSet2
19 years ago
Last year I had to pick the best Java networking technology for a project.
I evaluated Sockets, RMI, EJBs and HTTP (Tomcat). RMI was the fastest, about twice the speed of EJBs.

The major problem with RMI was the number of sockets wasted, 4 times more than for the other techs. This may be because:
- client connects to server;
- client connects to registry;
- server connects to registry;
- client connects to http server.

So this would make the RMI implementation I tested unusable for servers that must service hundreds of clients at the same time.

Another major problem were client callbacks. It seems the server needs to connect back to the client, the client acting like a server. But sometimes the IP address of the client machine is not accesible from the Internet, for example is the client is behind a firewall.

These RMI issues may have been resolved in Java 5.
I strongly encourage you to learn EJBs. They will not go away as corporations invested millions into software using the technology and most likely will embrace the next EJB3.0 which I doubt will be more useful and easier to use than current version.
I'm just curious, what hardware do you use?
Your server program (send) accepts a client connections, sends 3 String objects to the client and then terminates. The client connection is automatically closed which causes the exception on the client side.

Remove the sleep(400) call in 'receive' and you'll read all the strings.
try
{
...
}
catch( SocketTimeoutException timeoutEx )
{
// close client socket and reconnect
}
catch( InterruptedIOException interEx )
{
// exit application
}
To create an address based on an IP string:

InetAddress address = InetAddress.getByName( "216.138.2.43" );

Check out this tutorial:
http://java.sun.com/docs/books/tutorial/networking/sockets/index.html