User: pra
Date: 01/04/26 14:02:13
Added: src/main/org/jboss/jms/ra JmsConnectionFactoryImpl.java
JmsConnectionManager.java
JmsConnectionRequestInfo.java JmsCred.java
JmsLocalTransaction.java JmsLogger.java
JmsManagedConnection.java
JmsManagedConnectionFactory.java JmsMetaData.java
JmsSession.java JmsSessionFactoryImpl.java
Level.java TestClient.java
Log:
Added classes for a JMS connector resource adapter
Revision Changes Path
1.1 jboss/src/main/org/jboss/jms/ra/JmsConnectionFactoryImpl.java
Index: JmsConnectionFactoryImpl.java
===================================================================
/*
* Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.jms.ra;
import java.io.Serializable;
import javax.naming.Reference;
import javax.resource.Referenceable;
import javax.resource.ResourceException;
import javax.resource.spi.ManagedConnectionFactory;
import javax.resource.spi.ConnectionManager;
import javax.jms.JMSException;
import javax.jms.QueueConnection;
import javax.jms.TopicConnection;
import org.jboss.jms.ra.client.JmsConnectionFactory;
/**
* JmsConnectionFactoryImpl.java
*
*
* Created: Thu Apr 26 17:02:50 2001
*
* @author Peter Antman ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public class JmsConnectionFactoryImpl
implements JmsConnectionFactory,Serializable, Referenceable {
private Reference reference;
/**
* JmsRa own factory
*/
private ManagedConnectionFactory mcf;
/**
* Hook to the appserver
*/
private ConnectionManager cm;
public JmsConnectionFactoryImpl(ManagedConnectionFactory mcf,
ConnectionManager cm)
{
this.mcf = mcf;
this.cm = cm;
if (cm == null) {
// This is standalone usage, no appserver
this.cm = new JmsConnectionManager();
} else {
this.cm = cm;
}
}
public void setReference(Reference reference)
{
this.reference = reference;
}
public Reference getReference()
{
return reference;
}
// --- QueueConnectionFactory
public QueueConnection createQueueConnection()
throws JMSException
{
JmsSessionFactoryImpl s = new JmsSessionFactoryImpl(mcf,cm);
s.isTopic(Boolean.FALSE);
return s;
}
public QueueConnection createQueueConnection(String userName,
String password)
throws JMSException
{
JmsSessionFactoryImpl s = new JmsSessionFactoryImpl(mcf,cm);
s.isTopic(Boolean.FALSE);
s.setUserName(userName);
s.setPassword(password);
return s;
}
// --- TopicConnectionFactory
public TopicConnection createTopicConnection()
throws JMSException
{
JmsSessionFactoryImpl s = new JmsSessionFactoryImpl(mcf,cm);
s.isTopic(Boolean.TRUE);
return s;
}
public TopicConnection createTopicConnection(String userName,
String password)
throws JMSException
{
JmsSessionFactoryImpl s = new JmsSessionFactoryImpl(mcf,cm);
s.isTopic(Boolean.TRUE);
s.setUserName(userName);
s.setPassword(password);
return s;
}
} // JmsConnectionFactoryImpl
1.1 jboss/src/main/org/jboss/jms/ra/JmsConnectionManager.java
Index: JmsConnectionManager.java
===================================================================
/*
* Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.jms.ra;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionManager;
import javax.resource.spi.ManagedConnectionFactory;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.ManagedConnection;
/**
<p>The resource adapters own ConnectionManager, used in non managed
environments.
</p>
<p>
Will handle some of the houskeeping an appserver nomaly does.
</p>
*
* Created: Thu Mar 29 16:09:26 2001
*
* @author Peter Antman ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public class JmsConnectionManager implements ConnectionManager {
public JmsConnectionManager() {
}
public Object allocateConnection(ManagedConnectionFactory mcf,
ConnectionRequestInfo cxRequestInfo)
throws ResourceException{
ManagedConnection mc = mcf.createManagedConnection(null,cxRequestInfo);
return mc.getConnection(null,cxRequestInfo);
}
} // JmsConnectionManager
1.1 jboss/src/main/org/jboss/jms/ra/JmsConnectionRequestInfo.java
Index: JmsConnectionRequestInfo.java
===================================================================
/*
* Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.jms.ra;
import javax.resource.spi.ConnectionRequestInfo;
/**
* JmsConnectionRequestInfo.java
*
*
* Created: Thu Mar 29 16:29:55 2001
*
* @author Peter Antman ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public class JmsConnectionRequestInfo implements ConnectionRequestInfo {
private String userName;
private String password;
private boolean transacted = true;
private int acknowledgeMode;
private boolean isTopic = true;
public JmsConnectionRequestInfo(boolean transacted,
int acknowledgeMode,
boolean isTopic
) {
this.transacted = transacted;
this.acknowledgeMode = acknowledgeMode;
this.isTopic = isTopic;
}
//
public String getUserName()
{
return userName;
}
public void setUserName(String name)
{
userName = name;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
// End not used
public boolean isTransacted()
{
return transacted;
}
public int getAcknowledgeMode()
{
return acknowledgeMode;
}
public boolean isTopic() {
return isTopic;
}
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj instanceof JmsConnectionRequestInfo) {
JmsConnectionRequestInfo you = (JmsConnectionRequestInfo) obj;
return (this.transacted == you.isTransacted() &&
this.acknowledgeMode == you.getAcknowledgeMode() &&
this.isTopic == you.isTopic()
);
} else {
return false;
}
}
// FIXME !!
public int hashCode() {
String result = "" + transacted + acknowledgeMode + isTopic;
return result.hashCode();
}
// May be used if we fill in username and password later
private boolean isEqual(Object o1, Object o2) {
if (o1 == null) {
return (o2 == null);
} else {
return o1.equals(o2);
}
}
} // JmsConnectionRequestInfo
1.1 jboss/src/main/org/jboss/jms/ra/JmsCred.java
Index: JmsCred.java
===================================================================
/*
* Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.jms.ra;
import java.util.Set;
import java.util.Iterator;
import javax.security.auth.Subject;
import javax.resource.spi.ManagedConnectionFactory;
import javax.resource.spi.SecurityException;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.security.PasswordCredential;
/**
* JmsCred.java
*
*
* Created: Sat Mar 31 03:23:30 2001
*
* @author Peter Antman ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public class JmsCred {
public String name;
public String pwd;
public JmsCred() {
}
/**
* Get our own simple cred
*/
public static JmsCred getJmsCred(ManagedConnectionFactory mcf,
Subject subject,
ConnectionRequestInfo info)
throws SecurityException {
JmsCred jc = new JmsCred();
if (subject == null && info !=null ) {
// Credentials specifyed on connection request
jc.name = ((JmsConnectionRequestInfo)info).getUserName();
jc.pwd = ((JmsConnectionRequestInfo)info).getPassword();
} else if (subject != null) {
// Credentials from appserver
Set creds =
subject.getPrivateCredentials(PasswordCredential.class);
PasswordCredential pwdc = null;
Iterator credentials = creds.iterator();
while(credentials.hasNext()) {
PasswordCredential curCred =
(PasswordCredential) credentials.next();
if (curCred.getManagedConnectionFactory().equals(mcf)) {
pwdc = curCred;
break;
}
}
if(pwdc == null) {
// No hit - we do need creds
throw new SecurityException("No Passwdord credentials found");
}
jc.name = pwdc.getUserName();
jc.pwd = new String(pwdc.getPassword());
} else {
throw new SecurityException("No Subject or ConnectionRequestInfo set,
could not get credentials");
}
return jc;
}
} // JmsCred
1.1 jboss/src/main/org/jboss/jms/ra/JmsLocalTransaction.java
Index: JmsLocalTransaction.java
===================================================================
/*
* Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.jms.ra;
import javax.jms.JMSException;
import javax.resource.ResourceException;
import javax.resource.spi.LocalTransaction;
import javax.resource.spi.ConnectionEvent;
import javax.resource.spi.EISSystemException;
/**
* JmsLocalTransaction.java
*
*
* Created: Tue Apr 17 23:44:05 2001
*
* @author Peter Antman ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public class JmsLocalTransaction implements LocalTransaction {
JmsManagedConnection mc;
public JmsLocalTransaction(JmsManagedConnection mc) {
this.mc = mc;
}
public void begin() throws ResourceException {
// NOOP - begin is automatic in JMS
// Should probably send event
ConnectionEvent ev = new ConnectionEvent(mc,
ConnectionEvent.LOCAL_TRANSACTION_STARTED);
mc.sendEvent(ev);
}
public void commit() throws ResourceException {
try {
mc.getSession().commit();
ConnectionEvent ev = new ConnectionEvent(mc,
ConnectionEvent.LOCAL_TRANSACTION_COMMITTED);
mc.sendEvent(ev);
}catch(JMSException ex) {
ResourceException re = new EISSystemException("Could not commit
LocalTransaction : " + ex.getMessage());
re.setLinkedException(ex);
throw re;
}
}
public void rollback() throws ResourceException {
try {
mc.getSession().rollback();
ConnectionEvent ev = new ConnectionEvent(mc,
ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK);
mc.sendEvent(ev);
}catch(JMSException ex) {
ResourceException re = new EISSystemException("Could not rollback
LocalTransaction : " + ex.getMessage());
re.setLinkedException(ex);
throw re;
}
}
} // JmsLocalTransaction
1.1 jboss/src/main/org/jboss/jms/ra/JmsLogger.java
Index: JmsLogger.java
===================================================================
/*
* Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.jms.ra;
import java.io.PrintWriter;
/**
* JmsLogger.java
*
*
* Created: Tue Apr 17 21:21:49 2001
*
* @author Peter Antman ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public class JmsLogger {
private PrintWriter logWriter = null;
private boolean isOn = true;
private Level logLevel = Level.ALL;
public JmsLogger() {
logWriter = new PrintWriter(System.out);
}
public void setLogWriter(PrintWriter out) {
this.logWriter = out;
this.log(Level.FINE, "Setting LogWriter: " + out);
}
public void setLogging(boolean log) {
isOn = log;
}
public void setLogLevel(String level) {
logLevel = Level.parse(level);
}
public void log(Level level, String message) {
if(isOn && logLevel.intValue() >= level.intValue()) {
logWriter.println(level.toString() + ": " + message);
logWriter.flush();
}
}
} // JmsLogger
1.1 jboss/src/main/org/jboss/jms/ra/JmsManagedConnection.java
Index: JmsManagedConnection.java
===================================================================
/*
* Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.jms.ra;
import java.util.Vector;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
import java.io.PrintWriter;
import javax.security.auth.Subject;
import javax.transaction.xa.XAResource;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.jms.*;
import javax.resource.ResourceException;
import javax.resource.NotSupportedException;
import javax.resource.spi.ManagedConnectionFactory;
import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.ConnectionEventListener;
import javax.resource.spi.LocalTransaction;
import javax.resource.spi.ManagedConnectionMetaData;
import javax.resource.spi.CommException;
import javax.resource.spi.SecurityException;
import javax.resource.spi.IllegalStateException;
import javax.resource.spi.ConnectionEvent;
import org.jboss.jms.jndi.JMSProviderAdapter;
/**
<p>Managed Connection, manages one or more JMS sessions.
</p>
<p>Every ManagedConnection will have a physical JMSConnection under the hood. This
may leave out several session, as specifyed in 5.5.4 Multiple Connection Handles.
Thread safe semantics is provided.
</p>
<p>Hm. If we are to follow the example in 6.11 this will not work. We would have to
use the SAME session. This means we will have to guard against concurrent
access. We use a stack, and only allowes the handle at the top of the stack to do
things.
</p>
<p>As to transactions we some fairly hairy alternatives to handle:
XA - we get an XA. We may now only do transaction through the XAResource, since a
XASession MUST throw exceptions in commit etc. But since XA support implies
LocatTransaction support, we will have to use the XAResource in the LocalTransaction
class.
LocalTx - we get a normal session. The LocalTransaction will then work against the
normal session api.
An invokation of JMS MAY BE DONE in none transacted context. What do we do
then? How much should we leave to the user???
One possible solution is to use transactions any way, but under the hood. If not
LocalTransaction or XA has been aquired by the container, we have to do
the commit in send and publish. (CHECK is the container required to get a XA
every time it uses a managed connection? No its is not, only at creation!)
Does this mean that a session one time may be used in a transacted env, and
another time in a not transacted.
Maybe we could have this simple rule:
If a user is going to use non trans:
- mark that i ra deployment descr
- Use a JmsProviderAdapter with non XA factorys
- Mark session as non transacted (this defeats the purpose of specifying trans
attrinbutes in deploy descr NOT GOOD
From the JMS tutorial:
"When you create a session in an enterprise bean, the container ignores the
arguments you specify, because it manages all transactional properties for enterprise
beans."
And further:
"You do not specify a message acknowledgment mode when you create a message-driven
bean that uses container-managed transactions. The container handles
acknowledgment automatically."
On Session or Connection:
From Tutorial:
"A JMS API resource is a JMS API connection or a JMS API session." But in the
J2EE spec only connection is considered a resource.
Not resolved: connectionErrorOccurred: it is verry hard to know from the
exceptions thrown if it is a connection error. Should we register an
ExceptionListener and mark al handles as errounous? And then let them send the event
and throw an exception?
*
*
* Created: Tue Apr 10 13:09:45 2001
*
* @author Peter Antman ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public class JmsManagedConnection implements ManagedConnection{
private JmsManagedConnectionFactory mcf;
private JmsConnectionRequestInfo info;
private String user = null;
private String pwd = null;
private boolean isDestroyed = false;
// Physical JMS connection stuff
private Connection con;
// private TopicConnection topicConnection;
private TopicSession topicSession;
private XATopicSession xaTopicSession;
// private QueueConnection queueConnection;
private QueueSession queueSession;
private XAQueueSession xaQueueSession;
private XAResource xaResource;
// private boolean isTopic = true;
private boolean xaTransacted = true;
// Should we have one for each connection
private PrintWriter logWriter = null;
private JmsLogger logger = new JmsLogger();
// Holds all current JmsSession handles
private Set handles = new HashSet();
// The event listeners
Vector listeners = new Vector();
public JmsManagedConnection(JmsManagedConnectionFactory mcf,
ConnectionRequestInfo info,
String user,
String pwd) throws ResourceException
{
this.mcf = mcf;
this.info = (JmsConnectionRequestInfo)info;
this.user = user;
this.pwd = pwd;
setUp();
}
//---- ManagedConnection API ----
/**
Get the physical connection handler.
This bummer will be called in two situations.
1. When a new mc has bean created and a connection is needed
2. When an mc has been fetched from the pool (returned in match*)
It may also be called multiple time without a cleanup, to support
connection sharing
*/
public Object getConnection(Subject subject,
ConnectionRequestInfo info)
throws ResourceException {
// Check user first
JmsCred cred = JmsCred.getJmsCred(mcf,subject,info);
// Null users are allowed!
if (user != null && !user.equals(cred.name) )
throw new SecurityException("Password credentials not the same,
reauthentication not allowed");
if (cred.name != null && user == null)
throw new SecurityException("Password credentials not the same,
reauthentication not allowed");
user = cred.name; //Basically meaningless
if(isDestroyed)
throw new IllegalStateException("ManagedConnection already destroyd");
// Create a handle
JmsSession handle = new JmsSession(this);
handles.add(handle);
return handle;
}
/**
* Destroy the physical connection
*/
public void destroy() throws ResourceException {
if (isDestroyed) return;
isDestroyed = true;
// Destroy all handles
Iterator h = handles.iterator();
while(h.hasNext()) {
((JmsSession)h.next()).destroy();
}
handles.clear();
try {
// Close session and connection
if(info.isTopic()) {
topicSession.close();
if(xaTransacted)
xaTopicSession.close();
} else {
queueSession.close();
if(xaTransacted)
xaQueueSession.close();
}
con.close();
}catch(JMSException ex) {
ResourceException e = new ResourceException("Could not properly close the
session and connection: " + ex);
e.setLinkedException(ex);
throw e;
}
}
/**
* Cleans up the, from the spec
- The cleanup of ManagedConnection instance resets its client specific state.
Does that mean that autentication should be redone. FIXME
*/
public void cleanup() throws ResourceException {
if(isDestroyed)
throw new IllegalStateException("ManagedConnection already destroyd");
//
Iterator h = handles.iterator();
while(h.hasNext()) {
((JmsSession)h.next()).destroy();
}
handles.clear();
}
/**
* Move a handler from one mc to this one
*/
public void associateConnection(Object connection)
throws ResourceException {
// Should we check auth, ie user and pwd? FIXME
if(!isDestroyed &&
connection instanceof JmsSession) {
JmsSession h = (JmsSession) connection;
h.setManagedConnection(this);
handles.add(h);
}else {
throw new IllegalStateException("ManagedConnection in an illegal state");
}
}
public void addConnectionEventListener(ConnectionEventListener listener) {
logger.log(Level.FINE,"ConnectionEvent listener added");
listeners.addElement(listener);
}
public void removeConnectionEventListener(ConnectionEventListener listener) {
listeners.removeElement(listener);
}
public XAResource getXAResource() throws ResourceException {
/* Spec says a mc must allways return the same XA resource, so we
chaches it
*/
if (! xaTransacted)
throw new NotSupportedException("XA transaction not supported");
if (xaResource == null) {
if (info.isTopic())
xaResource = xaTopicSession.getXAResource();
else
xaResource = xaQueueSession.getXAResource();
}
logger.log(Level.FINE, "Leaving out XAResource");
return xaResource;
}
public LocalTransaction getLocalTransaction() throws ResourceException {
logger.log(Level.FINE, "Leaving out LocalTransaction");
return new JmsLocalTransaction(this);
}
public ManagedConnectionMetaData getMetaData() throws ResourceException {
if(isDestroyed)
throw new IllegalStateException("ManagedConnection already destroyd");
return new JmsMetaData(this);
}
public void setLogWriter(PrintWriter out) throws ResourceException {
this.logWriter = out;
if (out != null)
logger.setLogWriter(out);
}
public PrintWriter getLogWriter() throws ResourceException {
return logWriter;
}
// --- Api to JmsSession
protected Session getSession() {
if (info.isTopic()) {
return topicSession;
} else {
return queueSession;
}
}
protected JmsLogger getLogger() {
return logger;
}
protected void sendEvent(ConnectionEvent ev) {
logger.log(Level.FINE,"Sending connection event: " + ev.getId());
Vector list = (Vector) listeners.clone();
int size = list.size();
for (int i=0; i<size; i++) {
ConnectionEventListener listener =
(ConnectionEventListener) list.elementAt(i);
int type = ev.getId();
switch (type) {
case ConnectionEvent.CONNECTION_CLOSED:
listener.connectionClosed(ev);
break;
case ConnectionEvent.LOCAL_TRANSACTION_STARTED:
listener.localTransactionStarted(ev);
break;
case ConnectionEvent.LOCAL_TRANSACTION_COMMITTED:
listener.localTransactionCommitted(ev);
break;
case ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK:
listener.localTransactionRolledback(ev);
break;
case ConnectionEvent.CONNECTION_ERROR_OCCURRED:
listener.connectionErrorOccurred(ev);
break;
default:
throw new IllegalArgumentException("Illegal eventType: " +
type);
}
}
}
protected void removeHandle(JmsSession handle) {
handles.remove(handle);
}
//--- Used by MCF
protected ConnectionRequestInfo getInfo() {
return info;
}
protected JmsManagedConnectionFactory getManagedConnectionFactory() {
return mcf;
}
// --- Used bu MetaData
protected String getUserName() {
return user;
}
//---- Private helper methods
private void setUp() throws ResourceException
{
try {
JMSProviderAdapter adapter;
if (mcf.getJmsProviderAdapterJNDI() != null) {
// Get initial context
Context serverCtx = new InitialContext();
//Lokup adapter
adapter = (JMSProviderAdapter)serverCtx.
lookup(mcf.getJmsProviderAdapterJNDI());
} else {
adapter = mcf.getJmsProviderAdapter();
}
Context context = adapter.getInitialContext();
// Get connections
if (info.isTopic()) {
// Get connectionFactory
TopicConnectionFactory topicFactory =
(TopicConnectionFactory)context.
lookup(adapter.getTopicFactoryName());
// Set up connection
if(user != null)
{
logger.log(Level.FINE, "Creating topic connection with user: "
+ user + " passwd: " + pwd);
con = topicFactory.
createTopicConnection(user, pwd);
}
else
{
logger.log(Level.FINE, "Creating topic connection");
con = topicFactory.createTopicConnection();
}
} else {
// Get connectionFactory
QueueConnectionFactory queueFactory =
(QueueConnectionFactory)context.
lookup(adapter.getQueueFactoryName());
// Queue connection
if (user != null)
{
logger.log(Level.FINE, "Creating queue connection with user: "
+ user + " passwd: " + pwd);
con = queueFactory.
createQueueConnection(user,pwd);
}
else
{
logger.log(Level.FINE, "Creating queue connection");
con = queueFactory.createQueueConnection();
}
}
// Get sessions
boolean transacted = true;
int ack = Session.AUTO_ACKNOWLEDGE;
if (con instanceof XATopicConnection) {
xaTopicSession = ((XATopicConnection)con).createXATopicSession();
topicSession = xaTopicSession.getTopicSession();
xaTransacted = true;
} else if(con instanceof XAQueueConnection) {
xaQueueSession = ((XAQueueConnection)con).createXAQueueSession();
queueSession = xaQueueSession.getQueueSession();
xaTransacted = true;
} else if (con instanceof TopicConnection) {
topicSession = ((TopicConnection)con).createTopicSession(transacted,
ack);
logger.log(Level.WARNING,"WARNING: Using a non-XA TopicConnection. It
will not be able to participate in a Global UOW");
} else if(con instanceof QueueConnection) {
queueSession = ((QueueConnection)con).createQueueSession(transacted,
ack);
logger.log(Level.WARNING,"WARNING: Using a non-XA QueueConnection. It
will not be able to participate in a Global UOW");
} else {
logger.log(Level.SEVERE,"Error in getting session for con: " + con);
throw new ResourceException("Connection was not reconizable: " + con);
}
}catch(NamingException ne) {
CommException ce = new CommException(ne.toString());
ce.setLinkedException(ne);
throw ce;
}catch(JMSException je) {
CommException ce = new CommException(je.toString());
ce.setLinkedException(je);
throw ce;
}
}
} // JmsManagedConnection
1.1 jboss/src/main/org/jboss/jms/ra/JmsManagedConnectionFactory.java
Index: JmsManagedConnectionFactory.java
===================================================================
/*
* Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.jms.ra;
import java.util.Set;
import java.util.Iterator;
import java.io.PrintWriter;
import javax.security.auth.Subject;
import javax.resource.ResourceException;
import javax.resource.spi.ManagedConnectionFactory;
import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.ConnectionManager;
import javax.resource.spi.SecurityException;
import javax.resource.spi.IllegalStateException;
import javax.resource.spi.security.PasswordCredential;
import org.jboss.jms.jndi.JMSProviderAdapter;
/**
* JmsManagedConnectionFactory.java
*
*
* Created: Sat Mar 31 03:08:35 2001
*
* @author Peter Antman ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public class JmsManagedConnectionFactory implements ManagedConnectionFactory {
private PrintWriter logWriter = null;
private String providerJNDI;
private JmsLogger logger = new JmsLogger();
//For local access
private JMSProviderAdapter adapter;
public JmsManagedConnectionFactory() {
}
/**
* Create a "non managed" connection factory. No appserver involved
*/
public Object createConnectionFactory() throws ResourceException
{
return new JmsConnectionFactoryImpl(this, null);
}
/**
* Create a ConnectionFactory with appserver hook
*/
public Object createConnectionFactory(ConnectionManager cxManager)
throws ResourceException
{
return new JmsConnectionFactoryImpl(this, cxManager);
}
/**
* Create a new connection to manage in pool
*/
public ManagedConnection createManagedConnection(Subject subject,
ConnectionRequestInfo info)
throws ResourceException
{
JmsCred cred = JmsCred.getJmsCred(this,subject, info);
// OK we got autentication stuff
JmsManagedConnection mc = new JmsManagedConnection
(this, info,cred.name, cred.pwd);
// Set default logwriter according to spec
mc.setLogWriter(logWriter);
return mc;
}
/**
* Match a set of connections from the pool
*/
public ManagedConnection
matchManagedConnections(Set connectionSet,
Subject subject,
ConnectionRequestInfo info)
throws ResourceException {
// Get cred
JmsCred cred = JmsCred.getJmsCred(this,subject, info);
// Traverse the pooled connections and look for a match, return
// first found
Iterator connections = connectionSet.iterator();
while (connections.hasNext()) {
Object obj = connections.next();
// We only care for connections of our own type
if (obj instanceof JmsManagedConnection) {
// This is one from the pool
JmsManagedConnection mc = (JmsManagedConnection) obj;
// Check if we even created this on
ManagedConnectionFactory mcf =
mc.getManagedConnectionFactory();
// Only admit a connection if it has the same username as our
// asked for creds
// FIXME, Here we have a problem, jms connection
// may be anonymous, have a user name
if (
(mc.getUserName() == null ||
(mc.getUserName() != null &&
mc.getUserName().equals(cred.name))
) &&
mcf.equals(this)) {
// Now check if ConnectionInfo equals
if (info.equals( mc.getInfo() )) {
return mc;
}
}
}
}
return null;
}
/**
*
*/
public void setLogWriter(PrintWriter out)
throws ResourceException {
this.logWriter = out;
logger.setLogWriter(out);
}
/**
*
*/
public PrintWriter getLogWriter() throws ResourceException {
return logWriter;
}
// FIXME, what should be the unique identity of a ConnectionFactory for
// JMS, hard do say actually
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj instanceof JmsManagedConnectionFactory) {
String you = ((JmsManagedConnectionFactory) obj).
getJmsProviderAdapterJNDI();
String me = this.providerJNDI;
return (you == null) ? (me == null) : (you.equals(me));
} else {
return false;
}
}
public int hashCode() {
if (providerJNDI == null) {
return (new String("")).hashCode();
} else {
return providerJNDI.hashCode();
}
}
// --- Connfiguration API ---
public void setJmsProviderAdapterJNDI(String jndi) {
providerJNDI = jndi;
}
public String getJmsProviderAdapterJNDI() {
return providerJNDI;
}
/**
* For local access
*/
public void setJmsProviderAdapter(JMSProviderAdapter adapter) {
this.adapter = adapter;
}
public JMSProviderAdapter getJmsProviderAdapter() {
return adapter;
}
} // JmsManagedConnectionFactory
1.1 jboss/src/main/org/jboss/jms/ra/JmsMetaData.java
Index: JmsMetaData.java
===================================================================
/*
* Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.jms.ra;
import javax.resource.ResourceException;
import javax.resource.spi.ManagedConnectionMetaData;
/**
* JmsMetaData.java
*
*
* Created: Sat Mar 31 03:36:27 2001
*
* @author Peter Antman ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public class JmsMetaData implements ManagedConnectionMetaData {
private JmsManagedConnection mc;
public JmsMetaData(JmsManagedConnection mc) {
this.mc = mc;
}
public String getEISProductName() throws ResourceException {
return "JMS CA Resource Adapter";
}
public String getEISProductVersion() throws ResourceException {
return "0.1";//Is this possible to get another way
}
public int getMaxConnections() throws ResourceException {
// Dont know how to get this, from Jms, we
// set it to unlimited
return 0;
}
public String getUserName() throws ResourceException {
return mc.getUserName();
}
} // JmsMetaData
1.1 jboss/src/main/org/jboss/jms/ra/JmsSession.java
Index: JmsSession.java
===================================================================
/*
* Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.jms.ra;
import java.io.Serializable;
import javax.jms.*;
import javax.resource.spi.ConnectionEvent;
/**
* JmsSession.java
*
*
* Created: Tue Apr 17 22:39:45 2001
*
* @author Peter Antman ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public class JmsSession implements QueueSession, TopicSession {
private JmsManagedConnection mc = null;
public JmsSession(JmsManagedConnection mc) {
this.mc = mc;
}
// ---- Session API
public BytesMessage createBytesMessage() throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return mc.getSession().createBytesMessage();
}
public MapMessage createMapMessage() throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return mc.getSession().createMapMessage();
}
public Message createMessage() throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return mc.getSession().createMessage();
}
public ObjectMessage createObjectMessage() throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return mc.getSession().createObjectMessage();
}
public ObjectMessage createObjectMessage(Serializable object) throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return mc.getSession().createObjectMessage(object);
}
public StreamMessage createStreamMessage() throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return mc.getSession().createStreamMessage();
}
public TextMessage createTextMessage() throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return mc.getSession().createTextMessage();
}
public TextMessage createTextMessage(String string) throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return mc.getSession().createTextMessage(string);
}
public boolean getTransacted() throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return mc.getSession().getTransacted();
}
public MessageListener getMessageListener() throws JMSException
{
throw new javax.jms.IllegalStateException("Methid not allowed in J2EE");
}
public void setMessageListener(MessageListener listener) throws JMSException
{
throw new javax.jms.IllegalStateException("Methid not allowed in J2EE");
}
public void run()
{
throw new Error("Methid not allowed in J2EE");
}
public void close() throws JMSException
{
mc.getLogger().log(Level.FINE, "Closing session");
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
// Special stuff FIXME
mc.removeHandle(this);
ConnectionEvent ev = new ConnectionEvent(mc,
ConnectionEvent.CONNECTION_CLOSED);
ev.setConnectionHandle(this);
mc.sendEvent(ev);
mc = null;
}
// FIXME - is this really OK, probably not
public void commit() throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
mc.getSession().commit();
}
public void rollback() throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
mc.getSession().rollback();
}
public synchronized void recover() throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
mc.getSession().recover();
}
// --- TopicSession API
public Topic createTopic(String topicName) throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return ((TopicSession)mc.getSession()).createTopic(topicName);
}
public TopicSubscriber createSubscriber(Topic topic) throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return ((TopicSession)mc.getSession()).createSubscriber(topic);
}
public TopicSubscriber createSubscriber(Topic topic, String messageSelector,
boolean noLocal) throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return ((TopicSession)mc.getSession()).createSubscriber(topic,messageSelector,
noLocal);
}
public TopicSubscriber createDurableSubscriber(Topic topic, String name) throws
JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return ((TopicSession)mc.getSession()).createDurableSubscriber(topic, name);
}
public TopicSubscriber createDurableSubscriber(Topic topic, String name, String
messageSelector, boolean noLocal) throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return ((TopicSession)mc.getSession()).createDurableSubscriber(topic,
name,
messageSelector,
noLocal);
}
public TopicPublisher createPublisher(Topic topic) throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return ((TopicSession)mc.getSession()).createPublisher(topic);
}
public TemporaryTopic createTemporaryTopic() throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return ((TopicSession)mc.getSession()).createTemporaryTopic();
}
public void unsubscribe(String name) throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
((TopicSession)mc.getSession()).unsubscribe(name);
}
//--- QueueSession API
public QueueBrowser createBrowser(Queue queue) throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return ((QueueSession)mc.getSession()).createBrowser(queue);
}
public QueueBrowser createBrowser(Queue queue,String messageSelector) throws
JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return ((QueueSession)mc.getSession()).createBrowser(queue,messageSelector);
}
public Queue createQueue(String queueName) throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return ((QueueSession)mc.getSession()).createQueue(queueName);
}
public QueueReceiver createReceiver(Queue queue) throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return ((QueueSession)mc.getSession()).createReceiver(queue);
}
public QueueReceiver createReceiver(Queue queue, String messageSelector) throws
JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return ((QueueSession)mc.getSession()).createReceiver(queue, messageSelector);
}
public QueueSender createSender(Queue queue) throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return ((QueueSession)mc.getSession()).createSender(queue);
}
public TemporaryQueue createTemporaryQueue() throws JMSException
{
if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
return ((QueueSession)mc.getSession()).createTemporaryQueue();
}
// --- JmsManagedConnection api
void setManagedConnection(JmsManagedConnection mc) {
if (this.mc !=null) {
this.mc.removeHandle(this);
}
this.mc = mc;
}
void destroy() {
mc = null;
}
} // JmsSession
1.1 jboss/src/main/org/jboss/jms/ra/JmsSessionFactoryImpl.java
Index: JmsSessionFactoryImpl.java
===================================================================
/*
* Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.jms.ra;
import java.io.Serializable;
import javax.naming.Reference;
import javax.resource.Referenceable;
import javax.resource.ResourceException;
import javax.resource.spi.ManagedConnectionFactory;
import javax.resource.spi.ConnectionManager;
import javax.resource.spi.ConnectionRequestInfo;
import javax.jms.JMSException;
import javax.jms.ConnectionConsumer;
import javax.jms.ServerSessionPool;
import javax.jms.TopicSession;
import javax.jms.Topic;
import javax.jms.QueueSession;
import javax.jms.Queue;
import javax.jms.ExceptionListener;
import javax.jms.ConnectionMetaData;
import org.jboss.jms.ra.client.JmsSessionFactory;
/**
* JmsSessionFactoryImpl.java
*
*
* Created: Thu Mar 29 15:36:51 2001
*
* @author Peter Antman ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public class JmsSessionFactoryImpl implements JmsSessionFactory,Serializable,
Referenceable {
private static final String ISE = "This method is not applicatable in JMS
resource adapter";
private Reference reference;
// Used from JmsConnectionFactory
private String userName = null;
private String password = null;
private Boolean isTopic = null;
/**
* JmsRa own factory
*/
private ManagedConnectionFactory mcf;
/**
* Hook to the appserver
*/
private ConnectionManager cm;
public JmsSessionFactoryImpl(ManagedConnectionFactory mcf,
ConnectionManager cm)
{
this.mcf = mcf;
this.cm = cm;
if (cm == null) {
// This is standalone usage, no appserver
this.cm = new JmsConnectionManager();
} else {
this.cm = cm;
}
}
public void setReference(Reference reference) {
this.reference = reference;
}
public Reference getReference() {
return reference;
}
// --- API for JmsConnectionFactoryImpl
public void setUserName(String name)
{
userName = name;
}
public void setPassword(String password)
{
this.password = password;
}
public void isTopic(Boolean isTopic) {
this.isTopic = isTopic;
}
//---- QueueConnection ---
public QueueSession createQueueSession(boolean transacted,
int acknowledgeMode)
throws JMSException
{
try {
if(isTopic != null && isTopic == Boolean.TRUE)
throw new IllegalStateException("Cant get a queue session from a topic
connection");
JmsConnectionRequestInfo info =
new JmsConnectionRequestInfo(transacted,acknowledgeMode,false);
info.setUserName(userName);
info.setPassword(password);
return (QueueSession) cm.allocateConnection(
mcf,
info
);
}catch(ResourceException ex) {
JMSException je = new JMSException("Could not create a session: " + ex);
je.setLinkedException(ex);
throw je;
}
}
public ConnectionConsumer createConnectionConsumer(Queue queue,
String messageSelector,
ServerSessionPool sessionPool,
int maxMessages)
throws JMSException
{
throw new IllegalStateException(ISE);
}
//--- TopicConnection ---
public TopicSession createTopicSession(boolean transacted,
int acknowledgeMode)
throws JMSException
{
try {
if(isTopic != null && isTopic == Boolean.FALSE)
throw new IllegalStateException("Cant get a topic session from a
session connection");
JmsConnectionRequestInfo info =
new JmsConnectionRequestInfo(transacted,acknowledgeMode,true);
info.setUserName(userName);
info.setPassword(password);
return (TopicSession) cm.allocateConnection(mcf,
info
);
}catch(ResourceException ex) {
JMSException je = new JMSException("Could not create a session: " + ex);
je.setLinkedException(ex);
throw je;
}
}
public ConnectionConsumer createConnectionConsumer(Topic topic,
String messageSelector,
ServerSessionPool sessionPool,
int maxMessages)
throws JMSException
{
throw new IllegalStateException(ISE);
}
public ConnectionConsumer createDurableConnectionConsumer(Topic topic,
String subscriptionName,
String messageSelector,
ServerSessionPool sessionPool,
int maxMessages)
throws JMSException
{
throw new IllegalStateException(ISE);
}
//--- Al the Connection methods
public String getClientID() throws JMSException {throw new
IllegalStateException(ISE);}
public void setClientID(String cID) throws JMSException {throw new
IllegalStateException(ISE);}
public ConnectionMetaData getMetaData() throws JMSException {throw new
IllegalStateException(ISE);}
public ExceptionListener getExceptionListener() throws JMSException {throw new
IllegalStateException(ISE);}
public void setExceptionListener(ExceptionListener listener) throws JMSException
{throw new IllegalStateException(ISE);}
public void start() throws JMSException {throw new IllegalStateException(ISE);}
public void stop() throws JMSException {throw new IllegalStateException(ISE);}
public synchronized void close() throws JMSException {throw new
IllegalStateException(ISE);}
} // JmsSessionFactoryImpl
1.1 jboss/src/main/org/jboss/jms/ra/Level.java
Index: Level.java
===================================================================
/*
* Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.jms.ra;
/**
* Level.java
*
*
* Created: Tue Apr 17 21:26:13 2001
*
* @author Peter Antman ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public class Level {
private static final Level[] levels = {new Level("OFF", 0),
new Level("SEVERE", 1),
new Level("WARNING", 2),
new Level("INFO", 3),
new Level("CONFIG", 4),
new Level("FINE", 5),
new Level("ALL", 6)};
public static final Level OFF = levels[0];
public static final Level SEVERE = levels[1];
public static final Level WARNING = levels[2];
public static final Level INFO = levels[3];
public static final Level CONFIG =levels[4];
public static final Level FINE = levels[5];
public static final Level ALL = levels[6];
private String name;
private int value;
protected Level(String name, int value) {
this.name = name;
this.value = value;
}
public boolean equals(Object o) {
Level l = (Level)o;
return(this.value == l.intValue());
}
public final int intValue() {
return value;
}
public String toString() {
return name;
}
public static Level parse(String name) throws IllegalArgumentException{
// Try convert to int first
try {
int l = new Integer(name).intValue();
if (l < levels.length)
return levels[l];
else
throw new IllegalArgumentException("No level for number: " + l);
}catch(NumberFormatException ex) {//NOOP, try string instead
}
// are we here, do string stuff
for (int i = 0; i < levels.length;i++) {
if (name.equals(levels[i].toString())) {
return levels[i];
}
}
// If we go here we have an error
throw new IllegalArgumentException("No level for string: " + name);
}
} // Level
1.1 jboss/src/main/org/jboss/jms/ra/TestClient.java
Index: TestClient.java
===================================================================
/*
* Copyright (c) 2001 Peter Antman Tim <[EMAIL PROTECTED]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jboss.jms.ra;
import javax.jms.*;
import javax.naming.InitialContext;
import org.jboss.jms.ra.client.*;
/**
* TestClient for stand alone use. Basically verry uninteresting.
*
*
* Created: Sun Apr 22 19:10:27 2001
*
* @author Peter Antman ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public class TestClient {
public TestClient() {
}
public static void main(String[] args) {
try {
JmsManagedConnectionFactory f = new JmsManagedConnectionFactory();
f.setJmsProviderAdapter( new org.jboss.jms.jndi.JBossMQProvider());
//f.setLogging("true");
JmsConnectionFactory cf =
(JmsConnectionFactory)f.createConnectionFactory();
//FIXME - how to get LocalTransaction for standalone usage?
TopicConnection con = cf.createTopicConnection();
TopicSession ses = con.createTopicSession(true,
Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic)new InitialContext().lookup("topic/testTopic");
TopicPublisher pub = ses.createPublisher(topic);
TextMessage m = ses.createTextMessage("Hello world!");
pub.publish(m);
ses.commit();
ses.close();
}catch(Exception ex) {
System.err.println("Error: " + ex);
ex.printStackTrace();
}
}
} // TestClient
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development