User: chirino
Date: 01/07/10 19:28:35
Added: src/main/org/jbossmq/il/uil UILClientIL.java
UILClientILService.java UILServerIL.java
UILServerILService.java
UILServerILServiceMBean.java
Log:
This is the il package which now holds interfaces that are more straitfoward to
understand
and implement. Under this package we place the other ils that have been implemented.
All the ILs are now MBeans and are managed though JMX.
Revision Changes Path
1.1 jbossmq/src/main/org/jbossmq/il/uil/UILClientIL.java
Index: UILClientIL.java
===================================================================
/*
* JBossMQ, the OpenSource JMS implementation
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jbossmq.il.uil;
import javax.jms.Destination;
import javax.jms.JMSException;
import org.jbossmq.ReceiveRequest;
import org.jbossmq.SpyDestination;
import org.jbossmq.Connection;
import org.jbossmq.il.ClientIL;
import org.jbossmq.il.uil.multiplexor.SocketMultiplexor;
import java.io.ObjectInputStream;
import java.rmi.RemoteException;
import java.io.BufferedOutputStream;
import java.io.ObjectOutputStream;
import java.io.BufferedInputStream;
import java.io.IOException;
/**
* The RMI implementation of the ConnectionReceiver object
*
* @author Norbert Lataille ([EMAIL PROTECTED])
* @author Hiram Chirino ([EMAIL PROTECTED])
*
* @version $Revision: 1.1 $
*/
public class UILClientIL implements ClientIL, java.io.Serializable {
public void close() throws Exception {
}
synchronized public void deleteTemporaryDestination(SpyDestination dest)
throws Exception
{
checkSocket();
out.writeByte(m_deleteTemporaryDestination);
out.writeObject(dest);
waitAnswer();
}
synchronized public void receive(ReceiveRequest messages[]) throws Exception
{
cat.debug("Checking socket");
checkSocket();
cat.debug("Writing request");
out.writeByte(m_receive);
out.writeObject(messages);
cat.debug("Waiting for awnser");
waitAnswer();
cat.debug("Done");
}
final static org.apache.log4j.Category cat =
org.apache.log4j.Category.getInstance(UILClientIL.class);
private transient ObjectInputStream in;
static final int m_close = 2;
static final int m_deleteTemporaryDestination = 1;
static final int m_receive = 3;
transient SocketMultiplexor mSocket;
private transient ObjectOutputStream out;
protected void checkSocket() throws Exception {
if (out == null)
createConnection();
}
protected void createConnection() throws RemoteException
{
try {
in=new ObjectInputStream(new
BufferedInputStream(mSocket.getInputStream(2)));
out=new ObjectOutputStream(new
BufferedOutputStream(mSocket.getOutputStream(2)));
out.flush();
} catch (Exception e) {
throw new RemoteException("Cannot connect to the
ConnectionReceiver/Server");
}
}
protected void waitAnswer() throws Exception
{
Exception throwException=null;
try {
out.reset();
out.flush();
int val=in.readByte();
switch(val) {
case 1:
Exception e=(Exception)in.readObject();
throwException = new RemoteException("", e);
break;
}
} catch (IOException e) {
throw new RemoteException("Cannot contact the remote
object",e);
}
if( throwException != null )
throw throwException;
}
}
1.1 jbossmq/src/main/org/jbossmq/il/uil/UILClientILService.java
Index: UILClientILService.java
===================================================================
/*
* JBossMQ, the OpenSource JMS implementation
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jbossmq.il.uil;
import javax.jms.Destination;
import javax.jms.JMSException;
import org.jbossmq.ReceiveRequest;
import org.jbossmq.SpyDestination;
import org.jbossmq.Connection;
import org.jbossmq.il.ClientIL;
import org.jbossmq.il.ClientILService;
import java.net.Socket;
import java.io.ObjectInputStream;
import java.rmi.RemoteException;
import java.io.BufferedOutputStream;
import java.io.ObjectOutputStream;
import java.io.BufferedInputStream;
import java.io.IOException;
/**
* The RMI implementation of the ConnectionReceiver object
*
* @author Norbert Lataille ([EMAIL PROTECTED])
* @author Hiram Chirino ([EMAIL PROTECTED])
*
* @version $Revision: 1.1 $
*/
public class UILClientILService implements org.jbossmq.il.ClientILService, Runnable {
//the client IL
UILClientIL clientIL;
/**
* getClientIL method comment.
*/
public org.jbossmq.il.ClientIL getClientIL() throws java.lang.Exception {
return clientIL;
}
/**
* init method comment.
*/
public void init(org.jbossmq.Connection connection, java.util.Properties
props) throws java.lang.Exception {
this.connection = connection;
clientIL= new UILClientIL();
}
/**
* start method comment.
*/
public void start() throws java.lang.Exception {
running = true;
worker = new Thread(connection.threadGroup, this,
"UILClientILService");
worker.setDaemon(true);
worker.start();
}
/**
*
*/
public void stop() throws java.lang.Exception {
running = false;
worker.interrupt();
}
//A link on my connection
private Connection connection;
// Attributes ----------------------------------------------------
static final int m_close = 2;
static final int m_deleteTemporaryDestination = 1;
static final int m_receive = 3;
//Should this service be running ?
private boolean running;
//The thread that is doing the Socket reading work
Thread worker;
public void run() {
org.jbossmq.Log.log("UILClientILService.run()");
Socket socket = null;
int code = 0;
ObjectOutputStream out = null;
ObjectInputStream in = null;
try {
org.jbossmq.Log.log("getting streams");
UILServerIL serverIL = (UILServerIL)connection.getServerIL();
out = new ObjectOutputStream(new
BufferedOutputStream(serverIL.mSocket.getOutputStream(2)));
out.flush();
in = new ObjectInputStream(new
BufferedInputStream(serverIL.mSocket.getInputStream(2)));
} catch (IOException e) {
connection.asynchFailure("Could not initialize the UILClientIL
Service.", e);
running = false;
return;
}
while (running) {
try {
org.jbossmq.Log.log("Waiting for a request");
code = in.readByte();
org.jbossmq.Log.log("Got it");
} catch (IOException e) {
if (running)
break;
connection.asynchFailure("Connection failure", e);
break;
}
try {
switch (code) {
case m_receive:
connection.asynchDeliver((org.jbossmq.ReceiveRequest[])in.readObject());
break;
case m_deleteTemporaryDestination:
connection.asynchDeleteTemporaryDestination((SpyDestination) in.readObject());
break;
case m_close :
connection.asynchClose();
break;
default :
RemoteException e = new
RemoteException("UILClientIL invocation contained a bad method code.");
connection.asynchFailure("UILClientIL
invocation contained a bad method code.", e);
throw e;
}
//Everthing was OK
try {
out.writeByte(0);
out.flush();
} catch (IOException e) {
if (running)
break;
connection.asynchFailure("Connection failure",
e);
break;
}
} catch (Exception e) {
if (running)
break;
try {
out.writeByte(1);
out.writeObject(e);
out.reset();
out.flush();
} catch (IOException e2) {
connection.asynchFailure("Connection failure",
e2);
break;
}
}
}
running = false;
try {
out.close();
in.close();
} catch (IOException e) {
connection.asynchFailure("Error whle closing UILClientIL
connection", e);
return;
}
}
}
1.1 jbossmq/src/main/org/jbossmq/il/uil/UILServerIL.java
Index: UILServerIL.java
===================================================================
/*
* JBossMQ, the OpenSource JMS implementation
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jbossmq.il.uil;
import javax.jms.JMSException;
import javax.jms.Destination;
import javax.jms.Topic;
import javax.jms.Queue;
import javax.jms.TemporaryTopic;
import javax.jms.TemporaryQueue;
import org.jbossmq.TransactionRequest;
import org.jbossmq.SpyMessage;
import org.jbossmq.AcknowledgementRequest;
import org.jbossmq.SpyDestination;
import org.jbossmq.ConnectionToken;
import org.jbossmq.il.ServerIL;
import org.jbossmq.server.JMSServer;
import org.jbossmq.il.uil.multiplexor.SocketMultiplexor;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.io.BufferedOutputStream;
import java.io.BufferedInputStream;
/**
* The JVM implementation of the ServerIL object
*
* @author Hiram Chirino ([EMAIL PROTECTED])
* @author Norbert Lataille ([EMAIL PROTECTED])
*
* @version $Revision: 1.1 $
*/
public class UILServerIL implements ServerIL, java.io.Serializable, Cloneable {
/**
* Need to clone because there are instance variables tha can get
* clobbered. All Multiple connections can NOT share the same JVMServerIL
object
*/
public ServerIL cloneServerIL() throws Exception {
return (ServerIL)clone();
}
synchronized public void setConnectionToken(ConnectionToken dest) throws
Exception {
checkConnection();
out.writeByte(m_setSpyDistributedConnection);
out.writeObject(dest);
waitAnswer();
}
synchronized public String getID() throws Exception {
checkConnection();
out.writeByte(m_getID);
return (String) waitAnswer();
}
synchronized public void addMessage(ConnectionToken dc, SpyMessage val) throws
Exception {
checkConnection();
out.writeByte(m_addMessage);
out.writeObject(val);
waitAnswer();
}
synchronized public Topic createTopic(ConnectionToken dc, String dest) throws
JMSException, Exception {
checkConnection();
out.writeByte(m_createTopic);
out.writeObject(dest);
return (Topic) waitAnswer();
}
synchronized public Queue createQueue(ConnectionToken dc, String dest) throws
JMSException, Exception {
checkConnection();
out.writeByte(m_createQueue);
out.writeObject(dest);
return (Queue) waitAnswer();
}
synchronized public void deleteTemporaryDestination(ConnectionToken dc,
SpyDestination dest) throws JMSException, Exception {
checkConnection();
out.writeByte(m_deleteTemporaryDestination);
out.writeObject(dest);
waitAnswer();
}
synchronized public void checkID(String ID) throws JMSException, Exception {
checkConnection();
out.writeByte(m_checkID);
out.writeObject(ID);
waitAnswer();
}
synchronized public void connectionClosing(ConnectionToken dc) throws
JMSException, Exception {
checkConnection();
out.writeByte(m_connectionClosing);
waitAnswer();
}
synchronized public TemporaryQueue getTemporaryQueue(ConnectionToken dc)
throws JMSException, Exception {
checkConnection();
out.writeByte(m_getTemporaryQueue);
return (TemporaryQueue) waitAnswer();
}
synchronized public TemporaryTopic getTemporaryTopic(ConnectionToken dc)
throws JMSException, Exception {
checkConnection();
out.writeByte(m_getTemporaryTopic);
return (TemporaryTopic) waitAnswer();
}
synchronized public void acknowledge(ConnectionToken dc,
AcknowledgementRequest item) throws JMSException, Exception {
checkConnection();
out.writeByte(m_acknowledge);
out.writeObject(item);
waitAnswer();
}
synchronized public SpyMessage[] browse(ConnectionToken dc, Destination dest,
String selector) throws JMSException, Exception {
checkConnection();
out.writeByte(m_browse);
out.writeObject(dest);
out.writeObject(selector);
return (SpyMessage[]) waitAnswer();
}
synchronized public void listenerChange(ConnectionToken dc, int subscriberId,
boolean state) throws Exception, Exception {
checkConnection();
out.writeByte(m_listenerChange);
out.writeInt(subscriberId);
out.writeBoolean(state);
waitAnswer();
}
synchronized public SpyMessage receive(ConnectionToken dc, int subscriberId,
long wait) throws Exception, Exception {
checkConnection();
out.writeByte(m_receive);
out.writeInt(subscriberId);
out.writeLong(wait);
return (SpyMessage) waitAnswer();
}
synchronized public void setEnabled(ConnectionToken dc, boolean enabled)
throws JMSException, Exception {
checkConnection();
out.writeByte(m_setEnabled);
out.writeBoolean(enabled);
waitAnswer();
}
synchronized public void unsubscribe(ConnectionToken dc, int subscriptionId )
throws JMSException, Exception {
checkConnection();
out.writeByte(m_unsubscribe);
out.writeInt(subscriptionId);
waitAnswer();
}
synchronized public String checkUser(String userName, String password) throws
JMSException, Exception {
checkConnection();
out.writeByte(m_checkUser);
out.writeObject(userName);
out.writeObject(password);
return (String)waitAnswer();
}
synchronized public void subscribe(ConnectionToken dc,
org.jbossmq.Subscription s) throws JMSException, Exception {
checkConnection();
out.writeByte(m_subscribe);
out.writeObject(s);
waitAnswer();
}
synchronized public void transact(org.jbossmq.ConnectionToken dc,
TransactionRequest t) throws JMSException, Exception {
checkConnection();
out.writeByte(m_transact);
out.writeObject(t);
waitAnswer();
}
protected InetAddress addr;
protected transient ObjectInputStream in;
static final int m_acknowledge = 1;
static final int m_addMessage = 2;
static final int m_browse = 3;
static final int m_checkID = 4;
static final int m_checkUser = 19;
static final int m_connectionClosing = 5;
static final int m_createQueue = 6;
static final int m_createTopic = 7;
static final int m_deleteTemporaryDestination = 8;
static final int m_getID = 9;
static final int m_getTemporaryQueue = 10;
static final int m_getTemporaryTopic = 11;
static final int m_listenerChange = 12;
static final int m_receive = 13;
static final int m_setEnabled = 14;
static final int m_setSpyDistributedConnection = 15;
static final int m_subscribe = 16;
static final int m_transact = 17;
static final int m_unsubscribe = 18;
protected transient SocketMultiplexor mSocket;
protected transient ObjectOutputStream out;
//Remote stuff
protected int port;
protected void checkConnection() throws Exception {
if (mSocket == null)
createConnection();
}
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
protected void createConnection() throws Exception {
Socket socket = new Socket(addr, port);
mSocket = new SocketMultiplexor(socket);
out = new ObjectOutputStream(new
BufferedOutputStream(mSocket.getOutputStream(1)));
out.flush();
in = new ObjectInputStream(new
BufferedInputStream(mSocket.getInputStream(1)));
}
protected Object waitAnswer() throws Exception {
out.reset();
out.flush();
int val = in.readByte();
if (val == 0)
return null;
if (val == 1) {
return in.readObject();
} else {
Exception e = (Exception)in.readObject();
throw e;
}
}
public UILServerIL(InetAddress a, int port) {
this.addr = a;
this.port = port;
}
}
1.1 jbossmq/src/main/org/jbossmq/il/uil/UILServerILService.java
Index: UILServerILService.java
===================================================================
/*
* JBossMQ, the OpenSource JMS implementation
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jbossmq.il.uil;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.management.*;
import org.jboss.util.ServiceMBeanSupport;
import org.jbossmq.GenericConnectionFactory;
import org.jbossmq.il.ServerILJMXService;
import org.jbossmq.il.ServerIL;
import org.jbossmq.server.JMSServer;
import java.net.Socket;
import javax.jms.JMSException;
import javax.jms.Queue;
import org.jbossmq.SpyMessage;
import javax.jms.Topic;
import java.io.ObjectOutputStream;
import javax.jms.Destination;
import java.io.BufferedInputStream;
import java.net.ServerSocket;
import java.net.InetAddress;
import org.jbossmq.Subscription;
import org.jbossmq.ConnectionToken;
import javax.jms.TemporaryTopic;
import org.jbossmq.AcknowledgementRequest;
import org.jbossmq.il.uil.multiplexor.*;
import java.io.ObjectInputStream;
import java.rmi.RemoteException;
import java.io.BufferedOutputStream;
import javax.jms.TemporaryQueue;
import org.jbossmq.TransactionRequest;
import java.io.IOException;
import org.jbossmq.SpyDestination;
/**
* Implements the ServerILJMXService which is used to
* manage the JVM IL.
*
* @author Hiram Chirino ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public class UILServerILService extends ServerILJMXService implements
UILServerILServiceMBean, Runnable {
UILServerIL serverIL;
/**
* Gives this JMX service a name.
*/
public String getName() {
return "JBossMQ-UILServerIL";
}
/**
* Used to construct the GenericConnectionFactory (bindJNDIReferences() builds
it)
* @returns ServerIL the instance of this IL
*/
public ServerIL getServerIL() {
return serverIL;
}
/**
* Starts this IL, and binds it to JNDI
*/
public void startService() throws Exception {
running = true;
this.server = lookupJMSServer();
serverSocket = new ServerSocket(serverBindPort);
serverSocket.setSoTimeout(SO_TIMEOUT);
cat.info("JBossMQ UIL service available at :
"+InetAddress.getLocalHost().getHostAddress()+ ":"+ serverSocket.getLocalPort());
worker = new Thread(server.threadGroup, this,"UIL Worker");
worker.start();
serverIL = new UILServerIL(InetAddress.getLocalHost(),
serverSocket.getLocalPort());
bindJNDIReferences();
}
/**
* Stops this IL, and unbinds it from JNDI
*/
public void stopService() {
try {
running = false;
unbindJNDIReferences();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Used to construct the GenericConnectionFactory (bindJNDIReferences() builds
it)
* Sets up the connection properties need by a client to use this
* IL
*/
public java.util.Properties getClientConnectionProperties() {
Properties rc= new Properties();
rc.setProperty(GenericConnectionFactory.CLIENT_IL_SERVICE_KEY,
"org.jbossmq.il.uil.UILClientILService");
return rc;
}
org.apache.log4j.Category cat =
org.apache.log4j.Category.getInstance(UILServerILService.class);
static final int m_acknowledge = 1;
static final int m_addMessage = 2;
static final int m_browse = 3;
static final int m_checkID = 4;
static final int m_checkUser = 19;
static final int m_connectionClosing = 5;
static final int m_createQueue = 6;
static final int m_createTopic = 7;
static final int m_deleteTemporaryDestination = 8;
static final int m_getID = 9;
static final int m_getTemporaryQueue = 10;
static final int m_getTemporaryTopic = 11;
static final int m_listenerChange = 12;
static final int m_receive = 13;
static final int m_setEnabled = 14;
static final int m_setSpyDistributedConnection = 15;
static final int m_subscribe = 16;
static final int m_transact = 17;
static final int m_unsubscribe = 18;
boolean running;
//The server implementation
protected static JMSServer server;
int serverBindPort=0;
protected ServerSocket serverSocket;
static final int SO_TIMEOUT = 5000;
Thread worker;
public void run()
{
Socket socket = null;
SocketMultiplexor mSocket = null;
int code = 0;
ObjectOutputStream out=null;
ObjectInputStream in=null;
ConnectionToken connectionToken=null;
boolean closed = false;
try {
while( running && socket==null ) {
try {
socket = serverSocket.accept();
} catch ( java.io.InterruptedIOException e ) {
}
}
new Thread(this,"UIL Worker").start();
mSocket = new SocketMultiplexor(socket);
out = new ObjectOutputStream(new
BufferedOutputStream(mSocket.getOutputStream(1)));
out.flush();
in = new ObjectInputStream(new
BufferedInputStream(mSocket.getInputStream(1)));
} catch (IOException e) {
cat.warn("Could not initialize the UILServerIL Service.", e);
running = false;
return;
}
while (!closed && running) {
try {
//socket.setSoTimeout(SO_TIMEOUT);
code=in.readByte();
} catch ( java.io.InterruptedIOException e ) {
if( !closed && !running )
continue;
} catch (IOException e) {
if( closed || !running )
break;
cat.warn("Connection failure (1).", e);
break;
}
try {
Object result=null;
switch (code)
{
case m_setSpyDistributedConnection:
cat.debug("Setting up the UILClientIL
Connection");
connectionToken =
(ConnectionToken)in.readObject();
((UILClientIL)connectionToken.clientIL).mSocket = mSocket;
((UILClientIL)connectionToken.clientIL).createConnection();
cat.debug("The UILClientIL Connection is set
up");
break;
case m_acknowledge:
server.acknowledge(connectionToken,
(AcknowledgementRequest)in.readObject());
break;
case m_addMessage:
server.addMessage(connectionToken,
(SpyMessage)in.readObject());
break;
case m_browse:
result=server.browse(connectionToken,
(Destination)in.readObject(), (String)in.readObject());
break;
case m_checkID:
server.checkID((String)in.readObject());
break;
case m_connectionClosing:
server.connectionClosing(connectionToken);
closed = true;
break;
case this.m_createQueue:
result=(Queue)server.createQueue(connectionToken, (String)in.readObject());
break;
case m_createTopic:
result=(Topic)server.createTopic(connectionToken, (String)in.readObject());
break;
case m_deleteTemporaryDestination:
server.deleteTemporaryDestination(connectionToken, (SpyDestination)in.readObject());
break;
case this.m_getID:
result=server.getID();
break;
case m_getTemporaryQueue:
result=(TemporaryQueue)server.getTemporaryQueue(connectionToken);
break;
case m_getTemporaryTopic:
result=(TemporaryTopic)server.getTemporaryTopic(connectionToken);
break;
case m_listenerChange:
server.listenerChange(connectionToken,in.readInt(),in.readBoolean());
break;
case m_receive:
result=server.receive(connectionToken,in.readInt(), in.readLong());
break;
case m_setEnabled :
server.setEnabled(connectionToken,
in.readBoolean());
break;
case m_subscribe:
server.subscribe(connectionToken,
(Subscription)in.readObject());
break;
case m_transact:
server.transact(connectionToken,
(TransactionRequest)in.readObject());
break;
case m_unsubscribe:
server.unsubscribe(connectionToken,in.readInt());
break;
case m_checkUser:
result =
server.checkUser((String)in.readObject(), (String)in.readObject());
break;
default:
throw new RemoteException("Bad method
code !");
}
//Everthing was OK
try {
if (result==null)
out.writeByte(0);
else {
out.writeByte(1);
out.writeObject(result);
out.reset();
}
out.flush();
} catch (IOException e) {
if( closed )
break;
cat.warn("Connection failure (2).", e);
break;
}
} catch (Exception e) {
if( closed )
break;
try {
out.writeByte(2);
out.writeObject(e);
out.reset();
out.flush();
} catch (IOException e2) {
if( closed )
break;
cat.warn("Connection failure (3).", e);
break;
}
}
}
try {
if( !closed ) {
try {
server.connectionClosing(connectionToken);
} catch ( JMSException ignore ) {
}
}
mSocket.close();
} catch ( IOException e ) {
cat.warn("Connection failure during connection close.", e);
}
}
}
1.1 jbossmq/src/main/org/jbossmq/il/uil/UILServerILServiceMBean.java
Index: UILServerILServiceMBean.java
===================================================================
/*
* JBossMQ, the OpenSource JMS implementation
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jbossmq.il.uil;
import java.lang.Object;
/**
* This interface is used to define which methods will be exposed
* via JMX.
*/
public interface UILServerILServiceMBean extends
org.jbossmq.il.ServerILJMXServiceMBean
{
public static final String OBJECT_NAME = "JBossMQ:service=UILServerIL";
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development