You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2009/04/27 21:47:33 UTC
svn commit: r769131 - in
/incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms:
component/JmsComponentFactory.java component/JmsComponentImpl.java
util/Closable.java util/JmsProxyHandler.java util/JmsUtil.java
Author: gerdogdu
Date: Mon Apr 27 19:47:32 2009
New Revision: 769131
URL: http://svn.apache.org/viewvc?rev=769131&view=rev
Log:
OpenWebBeans JMS implementation. Updating proxy handler.
Added:
incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/Closable.java (with props)
Modified:
incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/component/JmsComponentFactory.java
incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/component/JmsComponentImpl.java
incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/JmsProxyHandler.java
incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/JmsUtil.java
Modified: incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/component/JmsComponentFactory.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/component/JmsComponentFactory.java?rev=769131&r1=769130&r2=769131&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/component/JmsComponentFactory.java (original)
+++ incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/component/JmsComponentFactory.java Mon Apr 27 19:47:32 2009
@@ -16,6 +16,9 @@
*/
package org.apache.webbeans.jms.component;
+import java.lang.annotation.Annotation;
+
+import org.apache.webbeans.annotation.DependentScopeLiteral;
import org.apache.webbeans.jms.JMSModel;
import org.apache.webbeans.util.Asserts;
@@ -38,6 +41,18 @@
Asserts.assertNotNull(model,"model parameter can not be null");
Asserts.assertNotNull(clazz, "clazz parameter can not be null");
- return new JmsComponentImpl<T>(model,clazz);
+ JmsComponentImpl<T> component = new JmsComponentImpl<T>(model,clazz);
+
+ component.addApiType(clazz);
+ component.setImplScopeType(new DependentScopeLiteral());
+
+ Annotation[] anns = model.getBindings();
+
+ for(Annotation a : anns)
+ {
+ component.addBindingType(a);
+ }
+
+ return component;
}
}
Modified: incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/component/JmsComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/component/JmsComponentImpl.java?rev=769131&r1=769130&r2=769131&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/component/JmsComponentImpl.java (original)
+++ incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/component/JmsComponentImpl.java Mon Apr 27 19:47:32 2009
@@ -27,6 +27,7 @@
import org.apache.webbeans.component.WebBeansType;
import org.apache.webbeans.exception.WebBeansException;
import org.apache.webbeans.jms.JMSModel;
+import org.apache.webbeans.jms.util.Closable;
import org.apache.webbeans.jms.util.JmsUtil;
public class JmsComponentImpl<T> extends AbstractComponent<T>
@@ -34,9 +35,7 @@
private JMSModel jmsModel = null;
private Class<T> jmsClass = null;
-
- private Object jmsObject;
-
+
JmsComponentImpl(JMSModel jmsModel, Class<T> jmsClass)
{
super(WebBeansType.JMS);
@@ -62,9 +61,12 @@
{
try
{
- Method method = jmsClass.getClass().getMethod("close", new Class[]{});
-
- method.invoke(this.jmsObject, new Object[]{});
+ if(instance != null)
+ {
+ Method method = Closable.class.getMethod("closeJMSObject", new Class[]{});
+
+ method.invoke(instance, new Object[]{});
+ }
}
catch (Exception e)
@@ -75,10 +77,6 @@
}
}
- public void setJmsObject(Object jmsObject)
- {
- this.jmsObject = jmsObject;
- }
public Class<T> getJmsClass()
{
Added: incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/Closable.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/Closable.java?rev=769131&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/Closable.java (added)
+++ incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/Closable.java Mon Apr 27 19:47:32 2009
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.webbeans.jms.util;
+
+public interface Closable
+{
+ public void closeJMSObject();
+
+}
\ No newline at end of file
Propchange: incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/Closable.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/JmsProxyHandler.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/JmsProxyHandler.java?rev=769131&r1=769130&r2=769131&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/JmsProxyHandler.java (original)
+++ incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/JmsProxyHandler.java Mon Apr 27 19:47:32 2009
@@ -1,18 +1,15 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
+ * or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
*/
package org.apache.webbeans.jms.util;
@@ -27,36 +24,34 @@
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
-import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.Session;
-import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
-
import org.apache.webbeans.exception.WebBeansException;
import org.apache.webbeans.jms.JMSModel;
import org.apache.webbeans.jms.JMSModel.JMSType;
import org.apache.webbeans.jms.component.JmsComponentImpl;
+import org.apache.webbeans.util.ClassUtil;
import javassist.util.proxy.MethodHandler;
public class JmsProxyHandler implements MethodHandler
{
private JmsComponentImpl<?> jmsComponent = null;
-
+
private static ConnectionFactory connectionFactory = null;
-
+
private AtomicBoolean cfSet = new AtomicBoolean(false);
+
+ private static Map<JMSType, Connection> connections = new ConcurrentHashMap<JMSType, Connection>();
+
+ private static Map<String, Destination> dests = new ConcurrentHashMap<String, Destination>();
- private static Map<JMSType,Connection> connections = new ConcurrentHashMap<JMSType, Connection>();
-
- private static Map<String,Topic> topics = new ConcurrentHashMap<String,Topic>();
-
- private static Map<String,Queue> queues = new ConcurrentHashMap<String,Queue>();
-
+ private Object jmsObject = null;
+
public JmsProxyHandler(JmsComponentImpl<?> jmsComponent)
{
this.jmsComponent = jmsComponent;
@@ -64,235 +59,248 @@
public Object invoke(Object instance, Method method, Method proceed, Object[] arguments) throws Exception
{
- Object cf = createOrReturnConnectionFactory();
-
- if(cf == null)
- {
- cf = createOrReturnQueueOrTopicConnection();
- }
-
-
- if(cf == null)
+ if(method.getName().equals("closeJMSObject"))
{
- cf = createOrReturnQueueOrTopic();
+ close();
- }
-
- if(cf == null)
- {
- cf = createSession();
- }
-
- if(cf == null)
- {
- cf = createMessageProducers();
+ return null;
}
- if(cf == null)
+ if (!ClassUtil.isObjectMethod(method.getName()))
{
- cf = createMessageConsumers();
+ Object cf = null;
+
+ if (this.jmsObject == null)
+ {
+ Class<?> jmsClazz = this.jmsComponent.getJmsClass();
+
+ if (cf == null && Connection.class.isAssignableFrom(jmsClazz))
+ {
+ cf = createOrReturnQueueOrTopicConnection();
+ }
+
+ if (cf == null && Destination.class.isAssignableFrom(jmsClazz))
+ {
+ cf = createOrReturnQueueOrTopic();
+
+ }
+
+ if (cf == null && Session.class.isAssignableFrom(jmsClazz))
+ {
+ cf = createSession();
+ }
+
+ if (cf == null && MessageProducer.class.isAssignableFrom(jmsClazz))
+ {
+ cf = createMessageProducers();
+ }
+
+ if (cf == null && MessageConsumer.class.isAssignableFrom(jmsClazz))
+ {
+ cf = createMessageConsumers();
+ }
+
+ if (method.getName().equals("close"))
+ {
+ throw new UnsupportedOperationException("close method is not supported for JMS resources");
+ }
+
+ if (cf == null)
+ {
+ throw new WebBeansException("JMS Resource type is not correct!. Does not create JMS resource object to handle request");
+ }
+
+ this.jmsObject = cf;
+ }
+ else
+ {
+ cf = this.jmsObject;
+ }
+
+ return method.invoke(cf, arguments);
}
-
- if(method.getName().equals("close"))
+ else
{
- throw new UnsupportedOperationException("close method is not supported for JMS resources");
+ return proceed.invoke(instance, arguments);
}
-
- this.jmsComponent.setJmsObject(cf);
-
- return method.invoke(cf, arguments);
}
private Object createOrReturnConnectionFactory()
{
- if(ConnectionFactory.class.isAssignableFrom(jmsComponent.getJmsClass()))
+ if (connectionFactory != null)
+ {
+ return connectionFactory;
+ }
+ else
{
- if(connectionFactory != null)
+ if (cfSet.compareAndSet(false, true))
{
+ connectionFactory = JmsUtil.getConnectionFactory();
+
return connectionFactory;
}
- else
- {
- if(cfSet.compareAndSet(false, true))
- {
- connectionFactory = JmsUtil.getConnectionFactory();
-
- return connectionFactory;
- }
- }
}
-
+
return null;
}
-
+
private Session createSession()
{
try
{
- if(Session.class.isAssignableFrom(jmsComponent.getJmsClass()))
- {
- Connection connection = createOrReturnQueueOrTopicConnection();
-
- return connection.createSession(false , Session.AUTO_ACKNOWLEDGE);
- }
-
-
- }catch(JMSException e)
+
+ Connection connection = createOrReturnQueueOrTopicConnection();
+
+ return connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ }
+ catch (JMSException e)
{
- throw new WebBeansException("Unable to create jms session",e);
+ throw new WebBeansException("Unable to create jms session", e);
}
-
- return null;
+
}
-
+
private MessageProducer createMessageProducers()
{
try
{
- if(MessageProducer.class.isAssignableFrom(jmsComponent.getJmsClass()))
- {
- return createSession().createProducer(createOrReturnQueueOrTopic());
- }
+ Connection connection = createOrReturnQueueOrTopicConnection();
+
+ return connection.createSession(false, Session.AUTO_ACKNOWLEDGE).createProducer(createOrReturnQueueOrTopic());
}
catch (JMSException e)
{
- throw new WebBeansException("Unable to create jms message producer",e);
+ throw new WebBeansException("Unable to create jms message producer", e);
}
-
- return null;
+
}
-
+
private MessageConsumer createMessageConsumers()
{
try
{
- if(MessageConsumer.class.isAssignableFrom(jmsComponent.getJmsClass()))
- {
- return createSession().createConsumer(createOrReturnQueueOrTopic());
- }
+ Connection connection = createOrReturnQueueOrTopicConnection();
+
+ return connection.createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(createOrReturnQueueOrTopic());
}
catch (JMSException e)
{
- throw new WebBeansException("Unable to create jms message producer",e);
+ throw new WebBeansException("Unable to create jms message producer", e);
}
-
- return null;
+
}
-
-
+
private Connection createOrReturnQueueOrTopicConnection()
{
JMSModel jmsModel = this.jmsComponent.getJmsModel();
-
+
try
{
- if(Connection.class.isAssignableFrom(jmsComponent.getJmsClass()))
+ if (jmsModel.getJmsType().equals(JMSType.QUEUE))
{
- if(jmsModel.getJmsType().equals(JMSType.QUEUE))
+ if (connections.containsKey(JMSType.QUEUE))
{
- if(connections.containsKey(JMSType.QUEUE))
- {
- return connections.get(JMSType.QUEUE);
- }
- else
- {
- QueueConnectionFactory ccf = (QueueConnectionFactory)connectionFactory;
- QueueConnection qc = ccf.createQueueConnection();
- connections.put(JMSType.QUEUE, qc);
-
- return qc;
- }
- }
- else if(jmsModel.getJmsType().equals(JMSType.TOPIC))
- {
- if(connections.containsKey(JMSType.TOPIC))
- {
- return connections.get(JMSType.TOPIC);
- }
- else
- {
- TopicConnectionFactory ccf = (TopicConnectionFactory)connectionFactory;
- TopicConnection qc = ccf.createTopicConnection();
- connections.put(JMSType.TOPIC, qc);
-
- return qc;
- }
-
+ return connections.get(JMSType.QUEUE);
+ }
+ else
+ {
+ QueueConnectionFactory ccf = (QueueConnectionFactory) createOrReturnConnectionFactory();
+ QueueConnection qc = ccf.createQueueConnection();
+ connections.put(JMSType.QUEUE, qc);
+
+ return qc;
}
}
-
-
- }catch(JMSException e)
+ else if (jmsModel.getJmsType().equals(JMSType.TOPIC))
+ {
+ if (connections.containsKey(JMSType.TOPIC))
+ {
+ return connections.get(JMSType.TOPIC);
+ }
+ else
+ {
+ TopicConnectionFactory ccf = (TopicConnectionFactory) createOrReturnConnectionFactory();
+ TopicConnection qc = ccf.createTopicConnection();
+ connections.put(JMSType.TOPIC, qc);
+
+ return qc;
+ }
+
+ }
+
+ }
+ catch (JMSException e)
{
- throw new WebBeansException("Unable to create jms connection",e);
+ throw new WebBeansException("Unable to create jms connection", e);
}
-
-
+
return null;
}
- private Destination createOrReturnQueueOrTopic()
+ private void close()
{
- JMSModel jmsModel = this.jmsComponent.getJmsModel();
- String jndiName = jmsModel.isJndiNameDefined() ? jmsModel.getJndiName() : jmsModel.getMappedName();
-
- if(Topic.class.isAssignableFrom(jmsComponent.getJmsClass()))
+ try
{
-
- if(topics.get(jndiName) != null)
+ if(this.jmsObject != null)
{
- return topics.get(jndiName);
+ Method method = this.jmsObject.getClass().getMethod("close", new Class[]{});
+
+ if(!method.isAccessible())
+ {
+ method.setAccessible(true);
+ }
+
+ method.invoke(this.jmsObject, new Object[]{});
}
-
- Topic res = (Topic)JmsUtil.getInstanceFromJndi(this.jmsComponent.getJmsModel(), this.jmsComponent.getJmsClass());
-
- topics.put(jndiName , res);
- return res;
}
-
- else if(Queue.class.isAssignableFrom(jmsComponent.getJmsClass()))
+ catch (Exception e)
{
-
- if(queues.get(jndiName) != null)
- {
- return queues.get(jndiName);
- }
-
- Queue res = (Queue)JmsUtil.getInstanceFromJndi(this.jmsComponent.getJmsModel(), this.jmsComponent.getJmsClass());
-
- queues.put(jndiName , res);
-
- return res;
+ throw new WebBeansException("Unable to close JMS resources");
}
-
- return null;
}
-
+
+ private Destination createOrReturnQueueOrTopic()
+ {
+ JMSModel jmsModel = this.jmsComponent.getJmsModel();
+ String jndiName = jmsModel.isJndiNameDefined() ? jmsModel.getJndiName() : jmsModel.getMappedName();
+
+ if (dests.get(jndiName) != null)
+ {
+ return dests.get(jndiName);
+ }
+
+ Destination res = (Destination) JmsUtil.getInstanceFromJndi(this.jmsComponent.getJmsModel(), this.jmsComponent.getJmsClass());
+
+ dests.put(jndiName, res);
+
+ return res;
+
+ }
+
public static void clearConnections()
{
try
{
connectionFactory = null;
-
- for(Connection connection : connections.values())
+
+ for (Connection connection : connections.values())
{
connection.close();
- }
-
+ }
+
connections = null;
-
- topics.clear();
- queues.clear();
-
- topics = null;
- queues = null;
-
- }catch(Exception e)
+
+ dests.clear();
+ dests = null;
+
+ }
+ catch (Exception e)
{
throw new WebBeansException(e);
}
}
-
+
}
Modified: incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/JmsUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/JmsUtil.java?rev=769131&r1=769130&r2=769131&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/JmsUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/util/JmsUtil.java Mon Apr 27 19:47:32 2009
@@ -157,8 +157,16 @@
try
{
ProxyFactory pf = new ProxyFactory();
- pf.setInterfaces(new Class<?>[] {Serializable.class,ConnectionFactory.class,
- Connection.class,MessageConsumer.class,MessageProducer.class,Session.class,Topic.class,Queue.class});
+ pf.setInterfaces(new Class<?>[] {Closable.class,
+ Serializable.class,
+ QueueConnection.class,
+ Queue.class,
+ QueueSender.class,
+ QueueSession.class,
+ Topic.class,
+ TopicConnection.class,
+ TopicSession.class,
+ TopicPublisher.class});
pf.setHandler(new JmsProxyHandler(jmsComponent));