[jboss-cvs] JBossAS SVN: r97166 - in projects/jboss-jca/tags: JBOSS_JCA_1_0_0_ALPHA6/core/src/main/java/org/jboss/jca/core/api and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Nov 30 09:38:21 EST 2009
Author: jesper.pedersen
Date: 2009-11-30 09:38:21 -0500 (Mon, 30 Nov 2009)
New Revision: 97166
Added:
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/core/src/main/java/org/jboss/jca/core/api/ConnectionManager.java
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/core/src/main/java/org/jboss/jca/core/connectionmanager/CachedConnectionManager.java
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/deployers/src/test/java/org/jboss/jca/test/deployers/annotations/AnnotationsTestCase.java
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/deployers/CloneableDeployer.java
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/KernelImpl.java
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/MainDeployerImpl.java
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/tools/findbugs/filter.xml
Removed:
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/core/src/main/java/org/jboss/jca/core/api/ConnectionManager.java
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/core/src/main/java/org/jboss/jca/core/connectionmanager/CachedConnectionManager.java
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/deployers/src/test/java/org/jboss/jca/test/deployers/annotations/AnnotationsTestCase.java
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/deployers/CloneableDeployer.java
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/KernelImpl.java
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/MainDeployerImpl.java
projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/tools/findbugs/filter.xml
Log:
JBoss JCA 1.0.0.Alpha6
Copied: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6 (from rev 97161, projects/jboss-jca/trunk)
Deleted: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/core/src/main/java/org/jboss/jca/core/api/ConnectionManager.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/ConnectionManager.java 2009-11-30 11:05:54 UTC (rev 97161)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/core/src/main/java/org/jboss/jca/core/api/ConnectionManager.java 2009-11-30 14:38:21 UTC (rev 97166)
@@ -1,35 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This 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.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.jca.core.api;
-
-/**
- * The JBoss specific connection manager interface.
- *
- * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
- * @version $Rev$
- */
-public interface ConnectionManager extends
- javax.resource.spi.ConnectionManager, java.io.Serializable
-{
-
-}
Copied: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/core/src/main/java/org/jboss/jca/core/api/ConnectionManager.java (from rev 97162, projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/ConnectionManager.java)
===================================================================
--- projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/core/src/main/java/org/jboss/jca/core/api/ConnectionManager.java (rev 0)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/core/src/main/java/org/jboss/jca/core/api/ConnectionManager.java 2009-11-30 14:38:21 UTC (rev 97166)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This 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.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.api;
+
+/**
+ * The JBoss specific connection manager interface.
+ *
+ * @author <a href="mailto:gurkanerdogdu at yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$
+ */
+public interface ConnectionManager extends javax.resource.spi.ConnectionManager, java.io.Serializable
+{
+}
Deleted: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/core/src/main/java/org/jboss/jca/core/connectionmanager/CachedConnectionManager.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/CachedConnectionManager.java 2009-11-30 11:05:54 UTC (rev 97161)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/core/src/main/java/org/jboss/jca/core/connectionmanager/CachedConnectionManager.java 2009-11-30 14:38:21 UTC (rev 97166)
@@ -1,642 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This 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.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.jca.core.connectionmanager;
-
-import org.jboss.jca.core.connectionmanager.listener.ConnectionCacheListener;
-import org.jboss.jca.core.connectionmanager.listener.ConnectionListener;
-import org.jboss.jca.core.connectionmanager.transaction.TransactionSynchronizer;
-import org.jboss.jca.spi.ComponentStack;
-
-import java.lang.reflect.Method;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.WeakHashMap;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-
-import javax.resource.ResourceException;
-import javax.resource.spi.ConnectionRequestInfo;
-import javax.transaction.Synchronization;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-import org.jboss.logging.Logger;
-
-import org.jboss.tm.TxUtils;
-import org.jboss.tm.usertx.UserTransactionListener;
-import org.jboss.tm.usertx.client.ServerVMClientUserTransaction.UserTransactionStartedListener;
-import org.jboss.util.Strings;
-
-/**
- * CacheConnectionManager.
- * @version $Rev$
- *
- */
-public class CachedConnectionManager implements
- UserTransactionStartedListener,
- UserTransactionListener,
- ComponentStack
-{
- /**Log instance*/
- private static Logger log = Logger.getLogger(CachedConnectionManager.class);
-
- /**Log trace*/
- private boolean trace;
-
- /**Debug flag*/
- private boolean debug;
-
- /**Error flag*/
- private boolean error;
-
- /**Transaction Manager instance*/
- private TransactionManager transactionManager;
-
- /**
- * ThreadLocal that holds current calling meta-programming aware
- * object, used in case someone is idiotic enough to cache a
- * connection between invocations.and want the spec required
- * behavior of it getting hooked up to an appropriate
- * ManagedConnection on each method invocation.
- */
- private final ThreadLocal<LinkedList<Object>> currentObjects = new ThreadLocal<LinkedList<Object>>();
-
- /**
- * The variable <code>objectToConnectionManagerMap</code> holds the
- * map of meta-aware object to set of connections it holds, used by
- * the idiot spec compliant behavior.
- */
- private final Map<KeyConnectionAssociation, Map<ConnectionCacheListener, Collection<ConnectionRecord>>>
- objectToConnectionManagerMap = new HashMap<KeyConnectionAssociation,
- Map<ConnectionCacheListener, Collection<ConnectionRecord>>>();
-
- /**
- * Connection stacktraces
- */
- private Map<Object, Throwable> connectionStackTraces = new WeakHashMap<Object, Throwable>();
-
- /**
- * Creates a new instance.
- */
- public CachedConnectionManager()
- {
- this.trace = log.isTraceEnabled();
- }
-
- /**
- * Gets transaction manager.
- * @return transaction manager
- */
- public TransactionManager getTransactionManager()
- {
- return transactionManager;
- }
-
- /**
- * Sets transaction manager.
- * @param transactionManager transaction manager
- */
- public void setTransactionManager(TransactionManager transactionManager)
- {
- this.transactionManager = transactionManager;
- }
-
-
- /**
- * {@inheritDoc}
- */
- public void userTransactionStarted() throws SystemException
- {
- KeyConnectionAssociation key = peekMetaAwareObject();
- if (trace)
- {
- log.trace("user tx started, key: " + key);
- }
- if (key == null)
- {
- return; //not participating properly in this management scheme.
- }
-
- Map<ConnectionCacheListener, Collection<ConnectionRecord>> cmToConnectionsMap = key.getCMToConnectionsMap();
- Iterator<Entry<ConnectionCacheListener, Collection<ConnectionRecord>>> cmToConnectionsMapIterator =
- cmToConnectionsMap.entrySet().iterator();
-
- while (cmToConnectionsMapIterator.hasNext())
- {
- Entry<ConnectionCacheListener, Collection<ConnectionRecord>> entry = cmToConnectionsMapIterator.next();
- ConnectionCacheListener cm = entry.getKey();
- Collection<ConnectionRecord> conns = entry.getValue();
-
- cm.transactionStarted(conns);
- }
- }
-
- /**
- *
- * @return stack last meta-aware object
- */
- KeyConnectionAssociation peekMetaAwareObject()
- {
- LinkedList<Object> stack = currentObjects.get();
- if (stack == null)
- {
- return null;
- }
-
- if (!stack.isEmpty())
- {
- return (KeyConnectionAssociation) stack.getLast();
- }
-
- else
- {
- return null;
- }
- }
-
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
- public void popMetaAwareObject(Set unsharableResources) throws ResourceException
- {
- LinkedList<Object> stack = currentObjects.get();
- KeyConnectionAssociation oldKey = (KeyConnectionAssociation) stack.removeLast();
- if (trace)
- {
- log.trace("popped object: " + Strings.defaultToString(oldKey));
- }
-
- if (!stack.contains(oldKey))
- {
- disconnect(oldKey, unsharableResources);
- } // end of if ()
-
- if (debug)
- {
- if (closeAll(oldKey.getCMToConnectionsMap()) && error)
- {
- throw new ResourceException("Some connections were not closed, " +
- "see the log for the allocation stacktraces");
- }
- }
-
- }
-
- /**
- * Register connection.
- * @param cm connection manager
- * @param cl connection listener
- * @param connection connection handle
- * @param cri connection request info.
- */
- public void registerConnection(ConnectionCacheListener cm, ConnectionListener cl,
- Object connection, ConnectionRequestInfo cri)
- {
- if (debug)
- {
- synchronized (connectionStackTraces)
- {
- connectionStackTraces.put(connection, new Throwable("STACKTRACE"));
- }
- }
-
- KeyConnectionAssociation key = peekMetaAwareObject();
-
- if (trace)
- {
- log.trace("registering connection from connection manager " + cm +
- ", connection : " + connection + ", key: " + key);
- }
-
- if (key == null)
- {
- return; //not participating properly in this management scheme.
- }
-
- ConnectionRecord cr = new ConnectionRecord(cl, connection, cri);
- Map<ConnectionCacheListener, Collection<ConnectionRecord>> cmToConnectionsMap = key.getCMToConnectionsMap();
- Collection<ConnectionRecord> conns = cmToConnectionsMap.get(cm);
- if (conns == null)
- {
- conns = new ArrayList<ConnectionRecord>();
- cmToConnectionsMap.put(cm, conns);
- }
-
- conns.add(cr);
- }
-
- /**
- * Unregister connection.
- * @param cm connection manager
- * @param connection connection handle
- */
- public void unregisterConnection(ConnectionCacheListener cm, Object connection)
- {
- if (debug)
- {
- CloseConnectionSynchronization cas = getCloseConnectionSynchronization(false);
- if (cas != null)
- {
- cas.remove(connection);
- }
-
- synchronized (connectionStackTraces)
- {
- connectionStackTraces.remove(connection);
- }
- }
-
- KeyConnectionAssociation key = peekMetaAwareObject();
-
- if (trace)
- {
- log.trace("unregistering connection from connection manager " + cm +
- ", object: " + connection + ", key: " + key);
- }
-
- if (key == null)
- {
- return; //not participating properly in this management scheme.
- }
-
- Map<ConnectionCacheListener, Collection<ConnectionRecord>> cmToConnectionsMap = key.getCMToConnectionsMap();
- Collection<ConnectionRecord> conns = cmToConnectionsMap.get(cm);
- if (conns == null)
- {
- return; // Can happen if connections are "passed" between contexts
- }
-
- for (Iterator<ConnectionRecord> i = conns.iterator(); i.hasNext();)
- {
- if ((i.next()).getConnection() == connection)
- {
- i.remove();
- return;
- }
- }
-
- throw new IllegalStateException("Trying to return an unknown connection2! " + connection);
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
- public void pushMetaAwareObject(final Object rawKey, Set unsharableResources) throws ResourceException
- {
- LinkedList<Object> stack = currentObjects.get();
- if (stack == null)
- {
- if (trace)
- {
- log.trace("new stack for key: " + Strings.defaultToString(rawKey));
- }
-
- stack = new LinkedList<Object>();
- currentObjects.set(stack);
- }
- else
- {
- if (trace)
- {
- log.trace("old stack for key: " + Strings.defaultToString(rawKey));
- }
- }
-
- KeyConnectionAssociation key = new KeyConnectionAssociation(rawKey);
- if (!stack.contains(key))
- {
- reconnect(key, unsharableResources);
- }
-
- stack.addLast(key);
- }
-
- /**
- * The <code>reconnect</code> method gets the cmToConnectionsMap
- * from objectToConnectionManagerMap, copies it to the key, and
- * reconnects all the connections in it.
- *
- * @param key a <code>KeyConnectionAssociation</code> value
- * @param unsharableResources a <code>Set</code> value
- * @exception ResourceException if an error occurs
- */
- @SuppressWarnings("unchecked")
- private void reconnect(KeyConnectionAssociation key, Set unsharableResources) throws ResourceException
- {
- Map<ConnectionCacheListener, Collection<ConnectionRecord>> cmToConnectionsMap = null;
- synchronized (objectToConnectionManagerMap)
- {
- cmToConnectionsMap = objectToConnectionManagerMap.get(key);
- if (cmToConnectionsMap == null)
- {
- return;
- }
- }
- key.setCMToConnectionsMap(cmToConnectionsMap);
- Iterator<Entry<ConnectionCacheListener, Collection<ConnectionRecord>>> cmToConnectionsMapIterator =
- cmToConnectionsMap.entrySet().iterator();
-
- while (cmToConnectionsMapIterator.hasNext())
- {
- Entry<ConnectionCacheListener, Collection<ConnectionRecord>> entry = cmToConnectionsMapIterator.next();
- ConnectionCacheListener cm = entry.getKey();
- Collection<ConnectionRecord> conns = entry.getValue();
-
- cm.reconnect(conns, unsharableResources);
- }
- }
-
- /**
- * Disconnect connections.
- * @param key key
- * @param unsharableResources resource
- * @throws ResourceException exception
- */
- @SuppressWarnings("unchecked")
- private void disconnect(KeyConnectionAssociation key, Set unsharableResources) throws ResourceException
- {
- Map<ConnectionCacheListener, Collection<ConnectionRecord>> cmToConnectionsMap = null;
- cmToConnectionsMap = key.getCMToConnectionsMap();
- if (!cmToConnectionsMap.isEmpty())
- {
- synchronized (objectToConnectionManagerMap)
- {
- objectToConnectionManagerMap.put(key, cmToConnectionsMap);
- }
- Iterator<Entry<ConnectionCacheListener, Collection<ConnectionRecord>>> cmToConnectionsMapIterator =
- cmToConnectionsMap.entrySet().iterator();
-
- while (cmToConnectionsMapIterator.hasNext())
- {
- Entry<ConnectionCacheListener, Collection<ConnectionRecord>> entry = cmToConnectionsMapIterator.next();
- ConnectionCacheListener cm = entry.getKey();
- Collection<ConnectionRecord> conns = entry.getValue();
-
- cm.disconnect(conns, unsharableResources);
- }
- }
- }
-
- /**
- * Describe <code>unregisterConnectionCacheListener</code> method here.
- * This is a shutdown method called by a connection manager. It will remove all reference
- * to that connection manager from the cache, so cached connections from that manager
- * will never be recoverable.
- * Possibly this method should not exist.
- *
- * @param cm a <code>ConnectionCacheListener</code> value
- */
- public void unregisterConnectionCacheListener(ConnectionCacheListener cm)
- {
- if (trace)
- {
- log.trace("unregisterConnectionCacheListener: " + cm);
- }
-
- synchronized (objectToConnectionManagerMap)
- {
- Iterator<Map<ConnectionCacheListener, Collection<ConnectionRecord>>> it =
- objectToConnectionManagerMap.values().iterator();
-
- while (it.hasNext())
- {
- Map<ConnectionCacheListener, Collection<ConnectionRecord>> cmToConnectionsMap = it.next();
- if (cmToConnectionsMap != null)
- {
- cmToConnectionsMap.remove(cm);
- }
- }
- }
- }
-
-
- /**
- * Close all connections.
- * @param cmToConnectionsMap connection manager to connections
- * @return true if close
- */
- private boolean closeAll(Map<ConnectionCacheListener, Collection<ConnectionRecord>> cmToConnectionsMap)
- {
- if (!debug)
- {
- return false;
- }
-
- boolean unclosed = false;
-
- Collection<Collection<ConnectionRecord>> connections = cmToConnectionsMap.values();
- if (connections.size() != 0)
- {
- for (Iterator<Collection<ConnectionRecord>> i = connections.iterator(); i.hasNext();)
- {
- Collection<ConnectionRecord> conns = i.next();
- for (Iterator<ConnectionRecord> j = conns.iterator(); j.hasNext();)
- {
- Object c = (j.next()).getConnection();
- CloseConnectionSynchronization cas = getCloseConnectionSynchronization(true);
- if (cas == null)
- {
- unclosed = true;
- closeConnection(c);
- }
- else
- {
- cas.add(c);
- }
- }
- }
- }
-
- return unclosed;
- }
-
- /**
- * Gets close sync. instance.
- * @param createIfNotFound create if not found
- * @return sync. instance
- */
- private CloseConnectionSynchronization getCloseConnectionSynchronization(boolean createIfNotFound)
- {
- try
- {
- Transaction tx = null;
- if (transactionManager != null)
- {
- tx = transactionManager.getTransaction();
- }
-
- if (tx != null)
- {
- TransactionSynchronizer.lock(tx);
- try
- {
- CloseConnectionSynchronization cas = (CloseConnectionSynchronization)
- TransactionSynchronizer.getCCMSynchronization(tx);
-
- if (cas == null && createIfNotFound && TxUtils.isActive(tx))
- {
- cas = new CloseConnectionSynchronization();
- TransactionSynchronizer.registerCCMSynchronization(tx, cas);
- }
-
- return cas;
- }
- finally
- {
- TransactionSynchronizer.unlock(tx);
- }
- }
- }
- catch (Throwable t)
- {
- log.debug("Unable to synchronize with transaction", t);
- }
-
- return null;
- }
-
-
- /**
- * Close connection handle.
- * @param connectionHandle connection handle
- */
- private void closeConnection(Object connectionHandle)
- {
- try
- {
- Throwable exception;
-
- synchronized (connectionStackTraces)
- {
- exception = connectionStackTraces.remove(connectionHandle);
- }
-
- Method m = connectionHandle.getClass().getMethod("close", new Class[]{});
-
- try
- {
- if (exception != null)
- {
- log.info("Closing a connection for you. Please close them yourself: " + connectionHandle, exception);
- }
- else
- {
- log.info("Closing a connection for you. Please close them yourself: " + connectionHandle);
- }
-
- m.invoke(connectionHandle, new Object[]{});
- }
- catch (Throwable t)
- {
- log.info("Throwable trying to close a connection for you, please close it yourself", t);
- }
- }
- catch (NoSuchMethodException nsme)
- {
- log.info("Could not find a close method on alleged connection objects. Please close your own connections.");
- }
- }
-
-
- /**
- * Close synch. class.
- */
- private class CloseConnectionSynchronization implements Synchronization
- {
- /**Connection handles*/
- CopyOnWriteArraySet<Object> connections = new CopyOnWriteArraySet<Object>();
-
- /**Closing flag*/
- AtomicBoolean closing = new AtomicBoolean(false);
-
- /**
- * Creates a new instance.
- */
- public CloseConnectionSynchronization()
- {
-
- }
-
- /**
- * Add new connection handle.
- * @param c connection handle
- */
- public void add(Object c)
- {
- if (closing.get())
- {
- return;
- }
- connections.add(c);
- }
-
- /**
- * Removes connection handle.
- * @param c connection handle
- */
- public void remove(Object c)
- {
- if (closing.get())
- {
- return;
- }
-
- connections.remove(c);
- }
-
- /**
- * {@inheritDoc}
- */
- public void beforeCompletion()
- {
- //No-action
- }
-
- /**
- * {@inheritDoc}
- */
- public void afterCompletion(int status)
- {
- closing.set(true);
-
- for (Iterator<Object> i = connections.iterator(); i.hasNext();)
- {
- closeConnection(i.next());
- }
-
- connections.clear();
- }
- }
-
-}
Copied: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/core/src/main/java/org/jboss/jca/core/connectionmanager/CachedConnectionManager.java (from rev 97162, projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/CachedConnectionManager.java)
===================================================================
--- projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/core/src/main/java/org/jboss/jca/core/connectionmanager/CachedConnectionManager.java (rev 0)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/core/src/main/java/org/jboss/jca/core/connectionmanager/CachedConnectionManager.java 2009-11-30 14:38:21 UTC (rev 97166)
@@ -0,0 +1,642 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This 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.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.connectionmanager;
+
+import org.jboss.jca.core.connectionmanager.listener.ConnectionCacheListener;
+import org.jboss.jca.core.connectionmanager.listener.ConnectionListener;
+import org.jboss.jca.core.connectionmanager.transaction.TransactionSynchronizer;
+import org.jboss.jca.spi.ComponentStack;
+
+import java.lang.reflect.Method;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import org.jboss.logging.Logger;
+
+import org.jboss.tm.TxUtils;
+import org.jboss.tm.usertx.UserTransactionListener;
+import org.jboss.tm.usertx.client.ServerVMClientUserTransaction.UserTransactionStartedListener;
+import org.jboss.util.Strings;
+
+/**
+ * CacheConnectionManager.
+ * @version $Rev$
+ *
+ */
+public class CachedConnectionManager implements
+ UserTransactionStartedListener,
+ UserTransactionListener,
+ ComponentStack
+{
+ /**Log instance*/
+ private static Logger log = Logger.getLogger(CachedConnectionManager.class);
+
+ /**Log trace*/
+ private boolean trace;
+
+ /**Debug flag*/
+ private boolean debug;
+
+ /**Error flag*/
+ private boolean error;
+
+ /**Transaction Manager instance*/
+ private TransactionManager transactionManager;
+
+ /**
+ * ThreadLocal that holds current calling meta-programming aware
+ * object, used in case someone is idiotic enough to cache a
+ * connection between invocations.and want the spec required
+ * behavior of it getting hooked up to an appropriate
+ * ManagedConnection on each method invocation.
+ */
+ private final ThreadLocal<LinkedList<Object>> currentObjects = new ThreadLocal<LinkedList<Object>>();
+
+ /**
+ * The variable <code>objectToConnectionManagerMap</code> holds the
+ * map of meta-aware object to set of connections it holds, used by
+ * the idiot spec compliant behavior.
+ */
+ private final Map<KeyConnectionAssociation, Map<ConnectionCacheListener, Collection<ConnectionRecord>>>
+ objectToConnectionManagerMap = new HashMap<KeyConnectionAssociation,
+ Map<ConnectionCacheListener, Collection<ConnectionRecord>>>();
+
+ /**
+ * Connection stacktraces
+ */
+ private Map<Object, Throwable> connectionStackTraces = new WeakHashMap<Object, Throwable>();
+
+ /**
+ * Creates a new instance.
+ */
+ public CachedConnectionManager()
+ {
+ this.trace = log.isTraceEnabled();
+ }
+
+ /**
+ * Gets transaction manager.
+ * @return transaction manager
+ */
+ public TransactionManager getTransactionManager()
+ {
+ return transactionManager;
+ }
+
+ /**
+ * Sets transaction manager.
+ * @param transactionManager transaction manager
+ */
+ public void setTransactionManager(TransactionManager transactionManager)
+ {
+ this.transactionManager = transactionManager;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void userTransactionStarted() throws SystemException
+ {
+ KeyConnectionAssociation key = peekMetaAwareObject();
+ if (trace)
+ {
+ log.trace("user tx started, key: " + key);
+ }
+ if (key == null)
+ {
+ return; //not participating properly in this management scheme.
+ }
+
+ Map<ConnectionCacheListener, Collection<ConnectionRecord>> cmToConnectionsMap = key.getCMToConnectionsMap();
+ Iterator<Entry<ConnectionCacheListener, Collection<ConnectionRecord>>> cmToConnectionsMapIterator =
+ cmToConnectionsMap.entrySet().iterator();
+
+ while (cmToConnectionsMapIterator.hasNext())
+ {
+ Entry<ConnectionCacheListener, Collection<ConnectionRecord>> entry = cmToConnectionsMapIterator.next();
+ ConnectionCacheListener cm = entry.getKey();
+ Collection<ConnectionRecord> conns = entry.getValue();
+
+ cm.transactionStarted(conns);
+ }
+ }
+
+ /**
+ *
+ * @return stack last meta-aware object
+ */
+ KeyConnectionAssociation peekMetaAwareObject()
+ {
+ LinkedList<Object> stack = currentObjects.get();
+ if (stack == null)
+ {
+ return null;
+ }
+
+ if (!stack.isEmpty())
+ {
+ return (KeyConnectionAssociation) stack.getLast();
+ }
+
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public void popMetaAwareObject(Set unsharableResources) throws ResourceException
+ {
+ LinkedList<Object> stack = currentObjects.get();
+ KeyConnectionAssociation oldKey = (KeyConnectionAssociation) stack.removeLast();
+ if (trace)
+ {
+ log.trace("popped object: " + Strings.defaultToString(oldKey));
+ }
+
+ if (!stack.contains(oldKey))
+ {
+ disconnect(oldKey, unsharableResources);
+ } // end of if ()
+
+ if (debug)
+ {
+ if (closeAll(oldKey.getCMToConnectionsMap()) && error)
+ {
+ throw new ResourceException("Some connections were not closed, " +
+ "see the log for the allocation stacktraces");
+ }
+ }
+
+ }
+
+ /**
+ * Register connection.
+ * @param cm connection manager
+ * @param cl connection listener
+ * @param connection connection handle
+ * @param cri connection request info.
+ */
+ public void registerConnection(ConnectionCacheListener cm, ConnectionListener cl,
+ Object connection, ConnectionRequestInfo cri)
+ {
+ if (debug)
+ {
+ synchronized (connectionStackTraces)
+ {
+ connectionStackTraces.put(connection, new Throwable("STACKTRACE"));
+ }
+ }
+
+ KeyConnectionAssociation key = peekMetaAwareObject();
+
+ if (trace)
+ {
+ log.trace("registering connection from connection manager " + cm +
+ ", connection : " + connection + ", key: " + key);
+ }
+
+ if (key == null)
+ {
+ return; //not participating properly in this management scheme.
+ }
+
+ ConnectionRecord cr = new ConnectionRecord(cl, connection, cri);
+ Map<ConnectionCacheListener, Collection<ConnectionRecord>> cmToConnectionsMap = key.getCMToConnectionsMap();
+ Collection<ConnectionRecord> conns = cmToConnectionsMap.get(cm);
+ if (conns == null)
+ {
+ conns = new ArrayList<ConnectionRecord>();
+ cmToConnectionsMap.put(cm, conns);
+ }
+
+ conns.add(cr);
+ }
+
+ /**
+ * Unregister connection.
+ * @param cm connection manager
+ * @param connection connection handle
+ */
+ public void unregisterConnection(ConnectionCacheListener cm, Object connection)
+ {
+ if (debug)
+ {
+ CloseConnectionSynchronization cas = getCloseConnectionSynchronization(false);
+ if (cas != null)
+ {
+ cas.remove(connection);
+ }
+
+ synchronized (connectionStackTraces)
+ {
+ connectionStackTraces.remove(connection);
+ }
+ }
+
+ KeyConnectionAssociation key = peekMetaAwareObject();
+
+ if (trace)
+ {
+ log.trace("unregistering connection from connection manager " + cm +
+ ", object: " + connection + ", key: " + key);
+ }
+
+ if (key == null)
+ {
+ return; //not participating properly in this management scheme.
+ }
+
+ Map<ConnectionCacheListener, Collection<ConnectionRecord>> cmToConnectionsMap = key.getCMToConnectionsMap();
+ Collection<ConnectionRecord> conns = cmToConnectionsMap.get(cm);
+ if (conns == null)
+ {
+ return; // Can happen if connections are "passed" between contexts
+ }
+
+ for (Iterator<ConnectionRecord> i = conns.iterator(); i.hasNext();)
+ {
+ if ((i.next()).getConnection() == connection)
+ {
+ i.remove();
+ return;
+ }
+ }
+
+ throw new IllegalStateException("Trying to return an unknown connection2! " + connection);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public void pushMetaAwareObject(final Object rawKey, Set unsharableResources) throws ResourceException
+ {
+ LinkedList<Object> stack = currentObjects.get();
+ if (stack == null)
+ {
+ if (trace)
+ {
+ log.trace("new stack for key: " + Strings.defaultToString(rawKey));
+ }
+
+ stack = new LinkedList<Object>();
+ currentObjects.set(stack);
+ }
+ else
+ {
+ if (trace)
+ {
+ log.trace("old stack for key: " + Strings.defaultToString(rawKey));
+ }
+ }
+
+ KeyConnectionAssociation key = new KeyConnectionAssociation(rawKey);
+ if (!stack.contains(key))
+ {
+ reconnect(key, unsharableResources);
+ }
+
+ stack.addLast(key);
+ }
+
+ /**
+ * The <code>reconnect</code> method gets the cmToConnectionsMap
+ * from objectToConnectionManagerMap, copies it to the key, and
+ * reconnects all the connections in it.
+ *
+ * @param key a <code>KeyConnectionAssociation</code> value
+ * @param unsharableResources a <code>Set</code> value
+ * @exception ResourceException if an error occurs
+ */
+ @SuppressWarnings("unchecked")
+ private void reconnect(KeyConnectionAssociation key, Set unsharableResources) throws ResourceException
+ {
+ Map<ConnectionCacheListener, Collection<ConnectionRecord>> cmToConnectionsMap = null;
+ synchronized (objectToConnectionManagerMap)
+ {
+ cmToConnectionsMap = objectToConnectionManagerMap.get(key);
+ if (cmToConnectionsMap == null)
+ {
+ return;
+ }
+ }
+ key.setCMToConnectionsMap(cmToConnectionsMap);
+ Iterator<Entry<ConnectionCacheListener, Collection<ConnectionRecord>>> cmToConnectionsMapIterator =
+ cmToConnectionsMap.entrySet().iterator();
+
+ while (cmToConnectionsMapIterator.hasNext())
+ {
+ Entry<ConnectionCacheListener, Collection<ConnectionRecord>> entry = cmToConnectionsMapIterator.next();
+ ConnectionCacheListener cm = entry.getKey();
+ Collection<ConnectionRecord> conns = entry.getValue();
+
+ cm.reconnect(conns, unsharableResources);
+ }
+ }
+
+ /**
+ * Disconnect connections.
+ * @param key key
+ * @param unsharableResources resource
+ * @throws ResourceException exception
+ */
+ @SuppressWarnings("unchecked")
+ private void disconnect(KeyConnectionAssociation key, Set unsharableResources) throws ResourceException
+ {
+ Map<ConnectionCacheListener, Collection<ConnectionRecord>> cmToConnectionsMap = null;
+ cmToConnectionsMap = key.getCMToConnectionsMap();
+ if (!cmToConnectionsMap.isEmpty())
+ {
+ synchronized (objectToConnectionManagerMap)
+ {
+ objectToConnectionManagerMap.put(key, cmToConnectionsMap);
+ }
+ Iterator<Entry<ConnectionCacheListener, Collection<ConnectionRecord>>> cmToConnectionsMapIterator =
+ cmToConnectionsMap.entrySet().iterator();
+
+ while (cmToConnectionsMapIterator.hasNext())
+ {
+ Entry<ConnectionCacheListener, Collection<ConnectionRecord>> entry = cmToConnectionsMapIterator.next();
+ ConnectionCacheListener cm = entry.getKey();
+ Collection<ConnectionRecord> conns = entry.getValue();
+
+ cm.disconnect(conns, unsharableResources);
+ }
+ }
+ }
+
+ /**
+ * Describe <code>unregisterConnectionCacheListener</code> method here.
+ * This is a shutdown method called by a connection manager. It will remove all reference
+ * to that connection manager from the cache, so cached connections from that manager
+ * will never be recoverable.
+ * Possibly this method should not exist.
+ *
+ * @param cm a <code>ConnectionCacheListener</code> value
+ */
+ public void unregisterConnectionCacheListener(ConnectionCacheListener cm)
+ {
+ if (trace)
+ {
+ log.trace("unregisterConnectionCacheListener: " + cm);
+ }
+
+ synchronized (objectToConnectionManagerMap)
+ {
+ Iterator<Map<ConnectionCacheListener, Collection<ConnectionRecord>>> it =
+ objectToConnectionManagerMap.values().iterator();
+
+ while (it.hasNext())
+ {
+ Map<ConnectionCacheListener, Collection<ConnectionRecord>> cmToConnectionsMap = it.next();
+ if (cmToConnectionsMap != null)
+ {
+ cmToConnectionsMap.remove(cm);
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Close all connections.
+ * @param cmToConnectionsMap connection manager to connections
+ * @return true if close
+ */
+ private boolean closeAll(Map<ConnectionCacheListener, Collection<ConnectionRecord>> cmToConnectionsMap)
+ {
+ if (!debug)
+ {
+ return false;
+ }
+
+ boolean unclosed = false;
+
+ Collection<Collection<ConnectionRecord>> connections = cmToConnectionsMap.values();
+ if (connections.size() != 0)
+ {
+ for (Iterator<Collection<ConnectionRecord>> i = connections.iterator(); i.hasNext();)
+ {
+ Collection<ConnectionRecord> conns = i.next();
+ for (Iterator<ConnectionRecord> j = conns.iterator(); j.hasNext();)
+ {
+ Object c = (j.next()).getConnection();
+ CloseConnectionSynchronization cas = getCloseConnectionSynchronization(true);
+ if (cas == null)
+ {
+ unclosed = true;
+ closeConnection(c);
+ }
+ else
+ {
+ cas.add(c);
+ }
+ }
+ }
+ }
+
+ return unclosed;
+ }
+
+ /**
+ * Gets close sync. instance.
+ * @param createIfNotFound create if not found
+ * @return sync. instance
+ */
+ private CloseConnectionSynchronization getCloseConnectionSynchronization(boolean createIfNotFound)
+ {
+ try
+ {
+ Transaction tx = null;
+ if (transactionManager != null)
+ {
+ tx = transactionManager.getTransaction();
+ }
+
+ if (tx != null)
+ {
+ TransactionSynchronizer.lock(tx);
+ try
+ {
+ CloseConnectionSynchronization cas = (CloseConnectionSynchronization)
+ TransactionSynchronizer.getCCMSynchronization(tx);
+
+ if (cas == null && createIfNotFound && TxUtils.isActive(tx))
+ {
+ cas = new CloseConnectionSynchronization();
+ TransactionSynchronizer.registerCCMSynchronization(tx, cas);
+ }
+
+ return cas;
+ }
+ finally
+ {
+ TransactionSynchronizer.unlock(tx);
+ }
+ }
+ }
+ catch (Throwable t)
+ {
+ log.debug("Unable to synchronize with transaction", t);
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Close connection handle.
+ * @param connectionHandle connection handle
+ */
+ private void closeConnection(Object connectionHandle)
+ {
+ try
+ {
+ Throwable exception;
+
+ synchronized (connectionStackTraces)
+ {
+ exception = connectionStackTraces.remove(connectionHandle);
+ }
+
+ Method m = connectionHandle.getClass().getMethod("close", new Class[]{});
+
+ try
+ {
+ if (exception != null)
+ {
+ log.info("Closing a connection for you. Please close them yourself: " + connectionHandle, exception);
+ }
+ else
+ {
+ log.info("Closing a connection for you. Please close them yourself: " + connectionHandle);
+ }
+
+ m.invoke(connectionHandle, new Object[]{});
+ }
+ catch (Throwable t)
+ {
+ log.info("Throwable trying to close a connection for you, please close it yourself", t);
+ }
+ }
+ catch (NoSuchMethodException nsme)
+ {
+ log.info("Could not find a close method on alleged connection objects. Please close your own connections.");
+ }
+ }
+
+
+ /**
+ * Close synch. class.
+ */
+ private class CloseConnectionSynchronization implements Synchronization
+ {
+ /**Connection handles*/
+ CopyOnWriteArraySet<Object> connections = new CopyOnWriteArraySet<Object>();
+
+ /**Closing flag*/
+ AtomicBoolean closing = new AtomicBoolean(false);
+
+ /**
+ * Creates a new instance.
+ */
+ public CloseConnectionSynchronization()
+ {
+
+ }
+
+ /**
+ * Add new connection handle.
+ * @param c connection handle
+ */
+ public void add(Object c)
+ {
+ if (closing.get())
+ {
+ return;
+ }
+ connections.add(c);
+ }
+
+ /**
+ * Removes connection handle.
+ * @param c connection handle
+ */
+ public void remove(Object c)
+ {
+ if (closing.get())
+ {
+ return;
+ }
+
+ connections.remove(c);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void beforeCompletion()
+ {
+ //No-action
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void afterCompletion(int status)
+ {
+ closing.set(true);
+
+ for (Iterator<Object> i = connections.iterator(); i.hasNext();)
+ {
+ closeConnection(i.next());
+ }
+
+ connections.clear();
+ }
+ }
+
+}
Deleted: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java 2009-11-30 11:05:54 UTC (rev 97161)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java 2009-11-30 14:38:21 UTC (rev 97166)
@@ -1,386 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This 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.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.jca.deployers.fungal;
-
-import org.jboss.jca.fungal.deployers.CloneableDeployer;
-import org.jboss.jca.fungal.deployers.DeployException;
-import org.jboss.jca.fungal.deployers.Deployer;
-import org.jboss.jca.fungal.deployers.Deployment;
-import org.jboss.jca.fungal.util.FileUtil;
-import org.jboss.jca.fungal.util.Injection;
-import org.jboss.jca.fungal.util.JarFilter;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.jboss.logging.Logger;
-
-import org.jboss.metadata.rar.jboss.BvGroupMetaData;
-import org.jboss.metadata.rar.jboss.JBossRA20Base;
-import org.jboss.metadata.rar.jboss.JBossRAMetaData;
-import org.jboss.metadata.rar.spec.AdminObjectMetaData;
-import org.jboss.metadata.rar.spec.ConfigPropertyMetaData;
-import org.jboss.metadata.rar.spec.ConnectionDefinitionMetaData;
-import org.jboss.metadata.rar.spec.ConnectorMetaData;
-import org.jboss.metadata.rar.spec.JCA16DTDMetaData;
-import org.jboss.metadata.rar.spec.JCA16DefaultNSMetaData;
-import org.jboss.metadata.rar.spec.JCA16MetaData;
-import org.jboss.metadata.rar.spec.MessageListenerMetaData;
-import org.jboss.papaki.AnnotationRepository;
-import org.jboss.papaki.AnnotationScanner;
-import org.jboss.papaki.AnnotationScannerFactory;
-
-/**
- * The RA deployer for JCA/SJC
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- * @author <a href="mailto:jeff.zhang at jboss.org">Jeff Zhang</a>
- */
-public class RADeployer implements CloneableDeployer
-{
- private static Logger log = Logger.getLogger(RADeployer.class);
- private static boolean trace = log.isTraceEnabled();
-
- /** Preform bean validation */
- private static AtomicBoolean beanValidation = new AtomicBoolean(true);
-
- /**
- * Constructor
- */
- public RADeployer()
- {
- }
-
- /**
- * Set if bean validation should be performed
- * @param value The value
- */
- public void setBeanValidation(boolean value)
- {
- beanValidation.set(value);
- }
-
- /**
- * Should bean validation be performed
- * @return True if validation; otherwise false
- */
- public boolean getBeanValidation()
- {
- return beanValidation.get();
- }
-
- /**
- * Deploy
- * @param url The url
- * @param parent The parent classloader
- * @return The deployment
- * @exception DeployException Thrown if an error occurs during deployment
- */
- public Deployment deploy(URL url, ClassLoader parent) throws DeployException
- {
- if (url == null || !(url.toExternalForm().endsWith(".rar") || url.toExternalForm().endsWith(".rar/")))
- return null;
-
- log.debug("Deploying: " + url.toExternalForm());
-
- ClassLoader oldTCCL = SecurityActions.getThreadContextClassLoader();
- try
- {
- File f = new File(url.toURI());
-
- if (!f.exists())
- throw new IOException("Archive " + url.toExternalForm() + " doesnt exists");
-
- File root = null;
-
- if (f.isFile())
- {
- FileUtil fileUtil = new FileUtil();
- File destination = new File(SecurityActions.getSystemProperty("jboss.jca.home"), "/tmp/");
- root = fileUtil.extract(f, destination);
- }
- else
- {
- root = f;
- }
-
- // Create classloader
- URL[] urls = getUrls(root);
- URLClassLoader cl = SecurityActions.createURLCLassLoader(urls, parent);
- SecurityActions.setThreadContextClassLoader(cl);
-
- // Parse metadata
- Metadata metadataHandler = new Metadata();
- ConnectorMetaData cmd = metadataHandler.getStandardMetaData(root);
- JBossRAMetaData jrmd = metadataHandler.getJBossMetaData(root);
- boolean isMetadataComplete = true;
-
- // Process annotations
- if (cmd == null || cmd.is16())
- {
- AnnotationScanner annotationScanner =
- AnnotationScannerFactory.getStrategy(AnnotationScannerFactory.JAVASSIST_INPUT_STREAM);
- AnnotationRepository annotationRepository = annotationScanner.scan(cl.getURLs(), cl);
-
- isMetadataComplete = false;
- if (cmd != null)
- {
- if (cmd instanceof JCA16MetaData)
- {
- JCA16MetaData jmd = (JCA16MetaData)cmd;
- isMetadataComplete = jmd.isMetadataComplete();
- }
- else if (cmd instanceof JCA16DefaultNSMetaData)
- {
- JCA16DefaultNSMetaData jmd = (JCA16DefaultNSMetaData)cmd;
- isMetadataComplete = jmd.isMetadataComplete();
- }
- else if (cmd instanceof JCA16DTDMetaData)
- {
- JCA16DTDMetaData jmd = (JCA16DTDMetaData)cmd;
- isMetadataComplete = jmd.isMetadataComplete();
- }
- }
-
- if (cmd == null || !isMetadataComplete)
- {
- Annotations annotator = new Annotations();
- cmd = annotator.process(cmd, annotationRepository);
- }
- }
-
- // Validate metadata
- metadataHandler.validate(cmd);
-
- // Merge metadata
- cmd = metadataHandler.merge(cmd, jrmd);
-
- // Create objects
- // And
- // Inject values
- List<Object> objects = new ArrayList<Object>();
- if (cmd != null)
- {
- // ResourceAdapter
- if (cmd.getRa() != null && cmd.getRa().getRaClass() != null)
- {
- initAndInject(cmd.getRa().getRaClass(),
- cmd.getRa().getConfigProperty(), objects, cl);
- }
-
- // ManagedConnectionFactory
- if (cmd.getRa() != null &&
- cmd.getRa().getOutboundRa() != null &&
- cmd.getRa().getOutboundRa().getConDefs() != null)
- {
- List<ConnectionDefinitionMetaData> cdMetas = cmd.getRa().getOutboundRa().getConDefs();
- if (cdMetas.size() > 0)
- {
- //mcfs = new ArrayList<Object>();
- for (ConnectionDefinitionMetaData cdMeta : cdMetas)
- {
- if (cdMeta.getManagedConnectionFactoryClass() != null)
- {
- initAndInject(cdMeta.getManagedConnectionFactoryClass(),
- cdMeta.getConfigProps(), objects, cl);
- }
- }
- }
- }
- // activationspec
- if (cmd.getRa() != null &&
- cmd.getRa().getInboundRa() != null &&
- cmd.getRa().getInboundRa().getMessageAdapter() != null &&
- cmd.getRa().getInboundRa().getMessageAdapter().getMessageListeners() != null)
- {
- List<MessageListenerMetaData> mlMetas = cmd.getRa().getInboundRa().
- getMessageAdapter().getMessageListeners();
- if (mlMetas.size() > 0)
- {
- for (MessageListenerMetaData mlMeta : mlMetas)
- {
- if (mlMeta.getActivationSpecType() != null && mlMeta.getActivationSpecType().getAsClass() != null)
- {
- initAndInject(mlMeta.getActivationSpecType().getAsClass(),
- mlMeta.getActivationSpecType().getConfigProps(), objects, cl);
- }
- }
- }
- }
-
- //adminobject
- if (cmd.getRa() != null &&
- cmd.getRa().getAdminObjects() != null)
- {
- List<AdminObjectMetaData> aoMetas = cmd.getRa().getAdminObjects();
- if (aoMetas.size() > 0)
- {
- for (AdminObjectMetaData aoMeta : aoMetas)
- {
- if (aoMeta.getAdminObjectImplementationClass() != null)
- {
- initAndInject(aoMeta.getAdminObjectImplementationClass(),
- aoMeta.getConfigProps(), objects, cl);
- }
- }
- }
- }
- }
-
-
- // Bean validation
- if (getBeanValidation())
- {
- JBossRA20Base jrmd20 = null;
- List<Class> groupsClasses = null;
- if (jrmd instanceof JBossRA20Base)
- {
- jrmd20 = (JBossRA20Base)jrmd;
- }
- if (jrmd20 != null && jrmd20.getBvGroupsList() != null && jrmd20.getBvGroupsList().size() > 0)
- {
- BvGroupMetaData bvGroups = jrmd20.getBvGroupsList().get(0);
- groupsClasses = new ArrayList<Class>();
- for (String group : bvGroups.getBvGroups())
- {
- groupsClasses.add(Class.forName(group, true, cl));
- }
- }
-
- if (objects != null && objects.size() > 0)
- {
- BeanValidation beanValidator = new BeanValidation();
- for (Object mcf : objects)
- {
- beanValidator.validate(mcf, groupsClasses);
- }
- }
- }
-
- // Activate deployment
-
- log.info("Deployed: " + url.toExternalForm());
-
- return new RADeployment(url, cl);
- }
- catch (DeployException de)
- {
- // Just rethrow
- throw de;
- }
- catch (Throwable t)
- {
- throw new DeployException("Deployment " + url.toExternalForm() + " failed", t);
- }
- finally
- {
- SecurityActions.setThreadContextClassLoader(oldTCCL);
- }
- }
-
- /**
- * initAndInject
- * @param mlMeta
- * @param mcfs
- * @param cl
- * @throws DeployException
- */
- private void initAndInject(String className, List<ConfigPropertyMetaData> cpMetas,
- List<Object> mcfs, URLClassLoader cl) throws DeployException
- {
- Object mcf = null;
- try
- {
- Class mcfClass = Class.forName(className, true, cl);
- mcf = mcfClass.newInstance();
- mcfs.add(mcf);
-
- if (mcf != null)
- {
- if (cpMetas != null)
- {
- Injection injector = new Injection();
- for (ConfigPropertyMetaData cpmd : cpMetas)
- {
- injector.inject(cpmd.getType(), cpmd.getName(), cpmd.getValue(), mcf);
- }
- }
- }
- }
- catch (ClassNotFoundException e)
- {
- log.trace("can't constractor " + className + " class");
- }
- catch (Throwable t)
- {
- throw new DeployException("Deployment " + className + " failed", t);
- }
-
- }
-
- /**
- * Get the URLs for the directory and all libraries located in the directory
- * @param directrory The directory
- * @return The URLs
- * @exception MalformedURLException MalformedURLException
- * @exception IOException IOException
- */
- private URL[] getUrls(File directory) throws MalformedURLException, IOException
- {
- List<URL> list = new LinkedList<URL>();
-
- if (directory.exists() && directory.isDirectory())
- {
- // Add directory
- list.add(directory.toURI().toURL());
-
- // Add the contents of the directory too
- File[] jars = directory.listFiles(new JarFilter());
-
- if (jars != null)
- {
- for (int j = 0; j < jars.length; j++)
- {
- list.add(jars[j].getCanonicalFile().toURI().toURL());
- }
- }
- }
- return list.toArray(new URL[list.size()]);
- }
-
- /**
- * Clone
- * @return The copy of the object
- * @exception CloneNotSupportedException Thrown if a copy can't be created
- */
- public Deployer clone() throws CloneNotSupportedException
- {
- return new RADeployer();
- }
-}
Copied: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java (from rev 97165, projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java)
===================================================================
--- projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java (rev 0)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java 2009-11-30 14:38:21 UTC (rev 97166)
@@ -0,0 +1,386 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This 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.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.deployers.fungal;
+
+import org.jboss.jca.fungal.deployers.CloneableDeployer;
+import org.jboss.jca.fungal.deployers.DeployException;
+import org.jboss.jca.fungal.deployers.Deployer;
+import org.jboss.jca.fungal.deployers.Deployment;
+import org.jboss.jca.fungal.util.FileUtil;
+import org.jboss.jca.fungal.util.Injection;
+import org.jboss.jca.fungal.util.JarFilter;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.jboss.logging.Logger;
+
+import org.jboss.metadata.rar.jboss.BvGroupMetaData;
+import org.jboss.metadata.rar.jboss.JBossRA20Base;
+import org.jboss.metadata.rar.jboss.JBossRAMetaData;
+import org.jboss.metadata.rar.spec.AdminObjectMetaData;
+import org.jboss.metadata.rar.spec.ConfigPropertyMetaData;
+import org.jboss.metadata.rar.spec.ConnectionDefinitionMetaData;
+import org.jboss.metadata.rar.spec.ConnectorMetaData;
+import org.jboss.metadata.rar.spec.JCA16DTDMetaData;
+import org.jboss.metadata.rar.spec.JCA16DefaultNSMetaData;
+import org.jboss.metadata.rar.spec.JCA16MetaData;
+import org.jboss.metadata.rar.spec.MessageListenerMetaData;
+import org.jboss.papaki.AnnotationRepository;
+import org.jboss.papaki.AnnotationScanner;
+import org.jboss.papaki.AnnotationScannerFactory;
+
+/**
+ * The RA deployer for JCA/SJC
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @author <a href="mailto:jeff.zhang at jboss.org">Jeff Zhang</a>
+ */
+public final class RADeployer implements CloneableDeployer
+{
+ private static Logger log = Logger.getLogger(RADeployer.class);
+ private static boolean trace = log.isTraceEnabled();
+
+ /** Preform bean validation */
+ private static AtomicBoolean beanValidation = new AtomicBoolean(true);
+
+ /**
+ * Constructor
+ */
+ public RADeployer()
+ {
+ }
+
+ /**
+ * Set if bean validation should be performed
+ * @param value The value
+ */
+ public void setBeanValidation(boolean value)
+ {
+ beanValidation.set(value);
+ }
+
+ /**
+ * Should bean validation be performed
+ * @return True if validation; otherwise false
+ */
+ public boolean getBeanValidation()
+ {
+ return beanValidation.get();
+ }
+
+ /**
+ * Deploy
+ * @param url The url
+ * @param parent The parent classloader
+ * @return The deployment
+ * @exception DeployException Thrown if an error occurs during deployment
+ */
+ public Deployment deploy(URL url, ClassLoader parent) throws DeployException
+ {
+ if (url == null || !(url.toExternalForm().endsWith(".rar") || url.toExternalForm().endsWith(".rar/")))
+ return null;
+
+ log.debug("Deploying: " + url.toExternalForm());
+
+ ClassLoader oldTCCL = SecurityActions.getThreadContextClassLoader();
+ try
+ {
+ File f = new File(url.toURI());
+
+ if (!f.exists())
+ throw new IOException("Archive " + url.toExternalForm() + " doesnt exists");
+
+ File root = null;
+
+ if (f.isFile())
+ {
+ FileUtil fileUtil = new FileUtil();
+ File destination = new File(SecurityActions.getSystemProperty("jboss.jca.home"), "/tmp/");
+ root = fileUtil.extract(f, destination);
+ }
+ else
+ {
+ root = f;
+ }
+
+ // Create classloader
+ URL[] urls = getUrls(root);
+ URLClassLoader cl = SecurityActions.createURLCLassLoader(urls, parent);
+ SecurityActions.setThreadContextClassLoader(cl);
+
+ // Parse metadata
+ Metadata metadataHandler = new Metadata();
+ ConnectorMetaData cmd = metadataHandler.getStandardMetaData(root);
+ JBossRAMetaData jrmd = metadataHandler.getJBossMetaData(root);
+ boolean isMetadataComplete = true;
+
+ // Process annotations
+ if (cmd == null || cmd.is16())
+ {
+ AnnotationScanner annotationScanner =
+ AnnotationScannerFactory.getStrategy(AnnotationScannerFactory.JAVASSIST_INPUT_STREAM);
+ AnnotationRepository annotationRepository = annotationScanner.scan(cl.getURLs(), cl);
+
+ isMetadataComplete = false;
+ if (cmd != null)
+ {
+ if (cmd instanceof JCA16MetaData)
+ {
+ JCA16MetaData jmd = (JCA16MetaData)cmd;
+ isMetadataComplete = jmd.isMetadataComplete();
+ }
+ else if (cmd instanceof JCA16DefaultNSMetaData)
+ {
+ JCA16DefaultNSMetaData jmd = (JCA16DefaultNSMetaData)cmd;
+ isMetadataComplete = jmd.isMetadataComplete();
+ }
+ else if (cmd instanceof JCA16DTDMetaData)
+ {
+ JCA16DTDMetaData jmd = (JCA16DTDMetaData)cmd;
+ isMetadataComplete = jmd.isMetadataComplete();
+ }
+ }
+
+ if (cmd == null || !isMetadataComplete)
+ {
+ Annotations annotator = new Annotations();
+ cmd = annotator.process(cmd, annotationRepository);
+ }
+ }
+
+ // Validate metadata
+ metadataHandler.validate(cmd);
+
+ // Merge metadata
+ cmd = metadataHandler.merge(cmd, jrmd);
+
+ // Create objects
+ // And
+ // Inject values
+ List<Object> objects = new ArrayList<Object>();
+ if (cmd != null)
+ {
+ // ResourceAdapter
+ if (cmd.getRa() != null && cmd.getRa().getRaClass() != null)
+ {
+ initAndInject(cmd.getRa().getRaClass(),
+ cmd.getRa().getConfigProperty(), objects, cl);
+ }
+
+ // ManagedConnectionFactory
+ if (cmd.getRa() != null &&
+ cmd.getRa().getOutboundRa() != null &&
+ cmd.getRa().getOutboundRa().getConDefs() != null)
+ {
+ List<ConnectionDefinitionMetaData> cdMetas = cmd.getRa().getOutboundRa().getConDefs();
+ if (cdMetas.size() > 0)
+ {
+ //mcfs = new ArrayList<Object>();
+ for (ConnectionDefinitionMetaData cdMeta : cdMetas)
+ {
+ if (cdMeta.getManagedConnectionFactoryClass() != null)
+ {
+ initAndInject(cdMeta.getManagedConnectionFactoryClass(),
+ cdMeta.getConfigProps(), objects, cl);
+ }
+ }
+ }
+ }
+ // activationspec
+ if (cmd.getRa() != null &&
+ cmd.getRa().getInboundRa() != null &&
+ cmd.getRa().getInboundRa().getMessageAdapter() != null &&
+ cmd.getRa().getInboundRa().getMessageAdapter().getMessageListeners() != null)
+ {
+ List<MessageListenerMetaData> mlMetas = cmd.getRa().getInboundRa().
+ getMessageAdapter().getMessageListeners();
+ if (mlMetas.size() > 0)
+ {
+ for (MessageListenerMetaData mlMeta : mlMetas)
+ {
+ if (mlMeta.getActivationSpecType() != null && mlMeta.getActivationSpecType().getAsClass() != null)
+ {
+ initAndInject(mlMeta.getActivationSpecType().getAsClass(),
+ mlMeta.getActivationSpecType().getConfigProps(), objects, cl);
+ }
+ }
+ }
+ }
+
+ //adminobject
+ if (cmd.getRa() != null &&
+ cmd.getRa().getAdminObjects() != null)
+ {
+ List<AdminObjectMetaData> aoMetas = cmd.getRa().getAdminObjects();
+ if (aoMetas.size() > 0)
+ {
+ for (AdminObjectMetaData aoMeta : aoMetas)
+ {
+ if (aoMeta.getAdminObjectImplementationClass() != null)
+ {
+ initAndInject(aoMeta.getAdminObjectImplementationClass(),
+ aoMeta.getConfigProps(), objects, cl);
+ }
+ }
+ }
+ }
+ }
+
+
+ // Bean validation
+ if (getBeanValidation())
+ {
+ JBossRA20Base jrmd20 = null;
+ List<Class> groupsClasses = null;
+ if (jrmd instanceof JBossRA20Base)
+ {
+ jrmd20 = (JBossRA20Base)jrmd;
+ }
+ if (jrmd20 != null && jrmd20.getBvGroupsList() != null && jrmd20.getBvGroupsList().size() > 0)
+ {
+ BvGroupMetaData bvGroups = jrmd20.getBvGroupsList().get(0);
+ groupsClasses = new ArrayList<Class>();
+ for (String group : bvGroups.getBvGroups())
+ {
+ groupsClasses.add(Class.forName(group, true, cl));
+ }
+ }
+
+ if (objects != null && objects.size() > 0)
+ {
+ BeanValidation beanValidator = new BeanValidation();
+ for (Object mcf : objects)
+ {
+ beanValidator.validate(mcf, groupsClasses);
+ }
+ }
+ }
+
+ // Activate deployment
+
+ log.info("Deployed: " + url.toExternalForm());
+
+ return new RADeployment(url, cl);
+ }
+ catch (DeployException de)
+ {
+ // Just rethrow
+ throw de;
+ }
+ catch (Throwable t)
+ {
+ throw new DeployException("Deployment " + url.toExternalForm() + " failed", t);
+ }
+ finally
+ {
+ SecurityActions.setThreadContextClassLoader(oldTCCL);
+ }
+ }
+
+ /**
+ * initAndInject
+ * @param mlMeta
+ * @param mcfs
+ * @param cl
+ * @throws DeployException
+ */
+ private void initAndInject(String className, List<ConfigPropertyMetaData> cpMetas,
+ List<Object> mcfs, URLClassLoader cl) throws DeployException
+ {
+ Object mcf = null;
+ try
+ {
+ Class mcfClass = Class.forName(className, true, cl);
+ mcf = mcfClass.newInstance();
+ mcfs.add(mcf);
+
+ if (mcf != null)
+ {
+ if (cpMetas != null)
+ {
+ Injection injector = new Injection();
+ for (ConfigPropertyMetaData cpmd : cpMetas)
+ {
+ injector.inject(cpmd.getType(), cpmd.getName(), cpmd.getValue(), mcf);
+ }
+ }
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ log.trace("can't constractor " + className + " class");
+ }
+ catch (Throwable t)
+ {
+ throw new DeployException("Deployment " + className + " failed", t);
+ }
+
+ }
+
+ /**
+ * Get the URLs for the directory and all libraries located in the directory
+ * @param directrory The directory
+ * @return The URLs
+ * @exception MalformedURLException MalformedURLException
+ * @exception IOException IOException
+ */
+ private URL[] getUrls(File directory) throws MalformedURLException, IOException
+ {
+ List<URL> list = new LinkedList<URL>();
+
+ if (directory.exists() && directory.isDirectory())
+ {
+ // Add directory
+ list.add(directory.toURI().toURL());
+
+ // Add the contents of the directory too
+ File[] jars = directory.listFiles(new JarFilter());
+
+ if (jars != null)
+ {
+ for (int j = 0; j < jars.length; j++)
+ {
+ list.add(jars[j].getCanonicalFile().toURI().toURL());
+ }
+ }
+ }
+ return list.toArray(new URL[list.size()]);
+ }
+
+ /**
+ * Clone
+ * @return The copy of the object
+ * @exception CloneNotSupportedException Thrown if a copy can't be created
+ */
+ public Deployer clone() throws CloneNotSupportedException
+ {
+ return new RADeployer();
+ }
+}
Deleted: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/deployers/src/test/java/org/jboss/jca/test/deployers/annotations/AnnotationsTestCase.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/test/java/org/jboss/jca/test/deployers/annotations/AnnotationsTestCase.java 2009-11-30 11:05:54 UTC (rev 97161)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/deployers/src/test/java/org/jboss/jca/test/deployers/annotations/AnnotationsTestCase.java 2009-11-30 14:38:21 UTC (rev 97166)
@@ -1,349 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This 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.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.jca.test.deployers.annotations;
-
-import org.jboss.jca.deployers.fungal.Annotations;
-import org.jboss.jca.embedded.EmbeddedJCA;
-import org.jboss.jca.fungal.deployers.DeployException;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-
-import org.jboss.logging.Logger;
-import org.jboss.metadata.rar.spec.ConnectorMetaData;
-import org.jboss.papaki.AnnotationRepository;
-import org.jboss.papaki.AnnotationScanner;
-import org.jboss.papaki.AnnotationScannerFactory;
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-//import org.junit.Ignore;
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-/**
- * Test cases for the annotations handling
- *
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- * @author <a href="mailto:jeff.zhang at jboss.org">Jeff Zhang</a>
- * @version $Revision: $
- */
-public class AnnotationsTestCase
-{
-
- // --------------------------------------------------------------------------------||
- // Class Members ------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- private static Logger log = Logger.getLogger(AnnotationsTestCase.class);
-
- /*
- * Embedded
- */
- private static EmbeddedJCA embedded;
-
- /*
- * Annotations
- */
- private Annotations annotations;
-
- // --------------------------------------------------------------------------------||
- // Tests --------------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * Process: Null arguemnts
- * @throws Throwable throwable exception
- */
- @Test(expected = DeployException.class)
- public void testProcessNullArguments() throws Throwable
- {
- annotations.process(null, null);
- }
-
- /**
- * Process: Null arguemnt for annotation repository
- * @throws Throwable throwable exception
- */
- @Test(expected = DeployException.class)
- public void testProcessNullAnnotationRepository() throws Throwable
- {
- ConnectorMetaData cmd = new ConnectorMetaData();
- annotations.process(cmd, null);
- }
-
- /**
- * Process: Null arguemnt for connector metadata
- * @throws Throwable throwable exception
- */
- @Test
- public void testProcessNullConnectorMetaData() throws Throwable
- {
- try
- {
- URL url = getURL("ra16inout.rar");
- AnnotationScanner asf = AnnotationScannerFactory.getDefault();
- AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
-
- annotations.process(null, ar);
- }
- catch (Throwable t)
- {
- fail(t.getMessage());
- }
- }
-
- /**
- * Process: Connector -- verification of the processConnector method
- * @throws Throwable throwable exception
- */
- @Test
- public void testProcessConnector() throws Throwable
- {
- try
- {
- URL url = getURL("ra16inoutanno.rar");
- System.out.println(url);
- AnnotationScanner asf = AnnotationScannerFactory.getDefault();
- AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
-
- annotations.process(null, ar);
- }
- catch (Throwable t)
- {
- fail(t.getMessage());
- }
- }
-
- /**
- * Process: Connector -- verification of the processConnector method
- * @throws Throwable throwable exception
- */
- @Test
- public void testProcessConnectorFail() throws Throwable
- {
- try
- {
- URL url = getURL("rafail2connector.rar");
- AnnotationScanner asf = AnnotationScannerFactory.getDefault();
- AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
-
- annotations.process(null, ar);
-
- fail("Success");
- }
- catch (Throwable t)
- {
- // Ok
- }
- }
-
- /**
- * Process: ConnectionDefinitions -- verification of the processConnectionDefinitions method
- * @throws Throwable throwable exception
- */
- @Test
- public void testProcessConnectionDefinitions() throws Throwable
- {
- try
- {
- URL url = getURL("ra16annoconndefs.rar");
- AnnotationScanner asf = AnnotationScannerFactory.getDefault();
- AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
-
- annotations.process(null, ar);
- }
- catch (Throwable t)
- {
- fail(t.getMessage());
- }
- }
-
-
- /**
- * Process: ConnectionDefinition -- verification of the processConnectionDefinition method
- * @throws Throwable throwable exception
- */
- @Test
- public void testProcessConnectionDefinition() throws Throwable
- {
- try
- {
- URL url = getURL("ra16annoconndef.rar");
- AnnotationScanner asf = AnnotationScannerFactory.getDefault();
- AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
-
- annotations.process(null, ar);
- }
- catch (Throwable t)
- {
- fail(t.getMessage());
- }
- }
-
- /**
- * Process: Activation -- verification of the processActivation method
- * @throws Throwable throwable exception
- */
- @Test
- public void testProcessActivation() throws Throwable
- {
- try
- {
- URL url = getURL("ra16annoactiv.rar");
- AnnotationScanner asf = AnnotationScannerFactory.getDefault();
- AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
-
- annotations.process(null, ar);
- }
- catch (Throwable t)
- {
- fail(t.getMessage());
- }
- }
-
- /**
- * Process: AuthenticationMechanism -- verification of the processAuthenticationMechanism method
- * @throws Throwable throwable exception
- */
- @Test
- public void testProcessAuthenticationMechanism() throws Throwable
- {
- try
- {
- URL url = getURL("ra16annoauthmech.rar");
- AnnotationScanner asf = AnnotationScannerFactory.getDefault();
- AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
-
- annotations.process(null, ar);
- }
- catch (Throwable t)
- {
- fail(t.getMessage());
- }
- }
-
- /**
- * Process: AdministeredObject -- verification of the processAdministeredObject method
- * @throws Throwable throwable exception
- */
- @Test
- public void testProcessAdministeredObject() throws Throwable
- {
- try
- {
- URL url = getURL("ra16annoadminobj.rar");
- AnnotationScanner asf = AnnotationScannerFactory.getDefault();
- AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
-
- annotations.process(null, ar);
- }
- catch (Throwable t)
- {
- fail(t.getMessage());
- }
- }
-
- /**
- * Process: ConfigProperty -- verification of the processConfigProperty method
- * @throws Throwable throwable exception
- */
- @Test
- public void testProcessConfigProperty() throws Throwable
- {
- try
- {
- URL url = getURL("ra16annoconfprop.rar");
- AnnotationScanner asf = AnnotationScannerFactory.getDefault();
- AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
-
- annotations.process(null, ar);
- }
- catch (Throwable t)
- {
- fail(t.getMessage());
- }
- }
-
- // --------------------------------------------------------------------------------||
- // Lifecycle Methods --------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * be run before the Test method.
- * @throws Throwable throwable exception
- */
- @Before
- public void setup() throws Throwable
- {
- annotations = new Annotations();
- }
-
- /**
- * causes that method to be run after the Test method.
- * @throws Throwable throwable exception
- */
- @After
- public void tearDown() throws Throwable
- {
- annotations = null;
- }
-
- /**
- * Lifecycle start, before the suite is executed
- * @throws Throwable throwable exception
- */
- @BeforeClass
- public static void beforeClass() throws Throwable
- {
- }
-
- /**
- * Lifecycle stop, after the suite is executed
- * @throws Throwable throwable exception
- */
- @AfterClass
- public static void afterClass() throws Throwable
- {
- }
-
- /**
- * Get the URL for a test archive
- * @param archive The name of the test archive
- * @return The URL to the archive
- * @throws Throwable throwable exception
- */
- public URL getURL(String archive) throws Throwable
- {
- String fileName = System.getProperty("archives.dir") + File.separator + archive;
- File f = new File(fileName);
-
- if (!f.exists())
- throw new IOException("Archive: " + fileName + " doesn't exists");
-
- return f.toURI().toURL();
- }
-}
Copied: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/deployers/src/test/java/org/jboss/jca/test/deployers/annotations/AnnotationsTestCase.java (from rev 97162, projects/jboss-jca/trunk/deployers/src/test/java/org/jboss/jca/test/deployers/annotations/AnnotationsTestCase.java)
===================================================================
--- projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/deployers/src/test/java/org/jboss/jca/test/deployers/annotations/AnnotationsTestCase.java (rev 0)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/deployers/src/test/java/org/jboss/jca/test/deployers/annotations/AnnotationsTestCase.java 2009-11-30 14:38:21 UTC (rev 97166)
@@ -0,0 +1,349 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This 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.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.test.deployers.annotations;
+
+import org.jboss.jca.deployers.fungal.Annotations;
+import org.jboss.jca.embedded.EmbeddedJCA;
+import org.jboss.jca.fungal.deployers.DeployException;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.jboss.logging.Logger;
+import org.jboss.metadata.rar.spec.ConnectorMetaData;
+import org.jboss.papaki.AnnotationRepository;
+import org.jboss.papaki.AnnotationScanner;
+import org.jboss.papaki.AnnotationScannerFactory;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+//import org.junit.Ignore;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Test cases for the annotations handling
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @author <a href="mailto:jeff.zhang at jboss.org">Jeff Zhang</a>
+ * @version $Revision: $
+ */
+public class AnnotationsTestCase
+{
+
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static Logger log = Logger.getLogger(AnnotationsTestCase.class);
+
+ /*
+ * Embedded
+ */
+ private static EmbeddedJCA embedded;
+
+ /*
+ * Annotations
+ */
+ private Annotations annotations;
+
+ // --------------------------------------------------------------------------------||
+ // Tests --------------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Process: Null arguemnts
+ * @throws Throwable throwable exception
+ */
+ @Test(expected = DeployException.class)
+ public void testProcessNullArguments() throws Throwable
+ {
+ annotations.process(null, null);
+ }
+
+ /**
+ * Process: Null arguemnt for annotation repository
+ * @throws Throwable throwable exception
+ */
+ @Test(expected = DeployException.class)
+ public void testProcessNullAnnotationRepository() throws Throwable
+ {
+ ConnectorMetaData cmd = new ConnectorMetaData();
+ annotations.process(cmd, null);
+ }
+
+ /**
+ * Process: Null arguemnt for connector metadata
+ * @throws Throwable throwable exception
+ */
+ @Test
+ public void testProcessNullConnectorMetaData() throws Throwable
+ {
+ try
+ {
+ URL url = getURL("ra16inout.rar");
+ AnnotationScanner asf = AnnotationScannerFactory.getDefault();
+ AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
+
+ annotations.process(null, ar);
+ }
+ catch (Throwable t)
+ {
+ fail(t.getMessage());
+ }
+ }
+
+ /**
+ * Process: Connector -- verification of the processConnector method
+ * @throws Throwable throwable exception
+ */
+ @Test
+ public void testProcessConnector() throws Throwable
+ {
+ try
+ {
+ URL url = getURL("ra16inoutanno.rar");
+ System.out.println(url);
+ AnnotationScanner asf = AnnotationScannerFactory.getDefault();
+ AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
+
+ annotations.process(null, ar);
+ }
+ catch (Throwable t)
+ {
+ fail(t.getMessage());
+ }
+ }
+
+ /**
+ * Process: Connector -- verification of the processConnector method
+ * @throws Throwable throwable exception
+ */
+ @Test
+ public void testProcessConnectorFail() throws Throwable
+ {
+ try
+ {
+ URL url = getURL("rafail2connector.rar");
+ AnnotationScanner asf = AnnotationScannerFactory.getDefault();
+ AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
+
+ annotations.process(null, ar);
+
+ fail("Success");
+ }
+ catch (Throwable t)
+ {
+ // Ok
+ }
+ }
+
+ /**
+ * Process: ConnectionDefinitions -- verification of the processConnectionDefinitions method
+ * @throws Throwable throwable exception
+ */
+ @Test
+ public void testProcessConnectionDefinitions() throws Throwable
+ {
+ try
+ {
+ URL url = getURL("ra16annoconndefs.rar");
+ AnnotationScanner asf = AnnotationScannerFactory.getDefault();
+ AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
+
+ annotations.process(null, ar);
+ }
+ catch (Throwable t)
+ {
+ fail(t.getMessage());
+ }
+ }
+
+
+ /**
+ * Process: ConnectionDefinition -- verification of the processConnectionDefinition method
+ * @throws Throwable throwable exception
+ */
+ @Test
+ public void testProcessConnectionDefinition() throws Throwable
+ {
+ try
+ {
+ URL url = getURL("ra16annoconndef.rar");
+ AnnotationScanner asf = AnnotationScannerFactory.getDefault();
+ AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
+
+ annotations.process(null, ar);
+ }
+ catch (Throwable t)
+ {
+ fail(t.getMessage());
+ }
+ }
+
+ /**
+ * Process: Activation -- verification of the processActivation method
+ * @throws Throwable throwable exception
+ */
+ @Test
+ public void testProcessActivation() throws Throwable
+ {
+ try
+ {
+ URL url = getURL("ra16annoactiv.rar");
+ AnnotationScanner asf = AnnotationScannerFactory.getDefault();
+ AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
+
+ annotations.process(null, ar);
+ }
+ catch (Throwable t)
+ {
+ fail(t.getMessage());
+ }
+ }
+
+ /**
+ * Process: AuthenticationMechanism -- verification of the processAuthenticationMechanism method
+ * @throws Throwable throwable exception
+ */
+ @Test
+ public void testProcessAuthenticationMechanism() throws Throwable
+ {
+ try
+ {
+ URL url = getURL("ra16annoauthmech.rar");
+ AnnotationScanner asf = AnnotationScannerFactory.getDefault();
+ AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
+
+ annotations.process(null, ar);
+ }
+ catch (Throwable t)
+ {
+ fail(t.getMessage());
+ }
+ }
+
+ /**
+ * Process: AdministeredObject -- verification of the processAdministeredObject method
+ * @throws Throwable throwable exception
+ */
+ @Test
+ public void testProcessAdministeredObject() throws Throwable
+ {
+ try
+ {
+ URL url = getURL("ra16annoadminobj.rar");
+ AnnotationScanner asf = AnnotationScannerFactory.getDefault();
+ AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
+
+ annotations.process(null, ar);
+ }
+ catch (Throwable t)
+ {
+ fail(t.getMessage());
+ }
+ }
+
+ /**
+ * Process: ConfigProperty -- verification of the processConfigProperty method
+ * @throws Throwable throwable exception
+ */
+ @Test
+ public void testProcessConfigProperty() throws Throwable
+ {
+ try
+ {
+ URL url = getURL("ra16annoconfprop.rar");
+ AnnotationScanner asf = AnnotationScannerFactory.getDefault();
+ AnnotationRepository ar = asf.scan(new URL[] {url}, Thread.currentThread().getContextClassLoader());
+
+ annotations.process(null, ar);
+ }
+ catch (Throwable t)
+ {
+ fail(t.getMessage());
+ }
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Lifecycle Methods --------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * be run before the Test method.
+ * @throws Throwable throwable exception
+ */
+ @Before
+ public void setup() throws Throwable
+ {
+ annotations = new Annotations();
+ }
+
+ /**
+ * causes that method to be run after the Test method.
+ * @throws Throwable throwable exception
+ */
+ @After
+ public void tearDown() throws Throwable
+ {
+ annotations = null;
+ }
+
+ /**
+ * Lifecycle start, before the suite is executed
+ * @throws Throwable throwable exception
+ */
+ @BeforeClass
+ public static void beforeClass() throws Throwable
+ {
+ }
+
+ /**
+ * Lifecycle stop, after the suite is executed
+ * @throws Throwable throwable exception
+ */
+ @AfterClass
+ public static void afterClass() throws Throwable
+ {
+ }
+
+ /**
+ * Get the URL for a test archive
+ * @param archive The name of the test archive
+ * @return The URL to the archive
+ * @throws Throwable throwable exception
+ */
+ public URL getURL(String archive) throws Throwable
+ {
+ String fileName = System.getProperty("archives.dir") + File.separator + archive;
+ File f = new File(fileName);
+
+ if (!f.exists())
+ throw new IOException("Archive: " + fileName + " doesn't exists");
+
+ return f.toURI().toURL();
+ }
+}
Deleted: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/deployers/CloneableDeployer.java
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployers/CloneableDeployer.java 2009-11-30 11:05:54 UTC (rev 97161)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/deployers/CloneableDeployer.java 2009-11-30 14:38:21 UTC (rev 97166)
@@ -1,40 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This 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.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.jca.fungal.deployers;
-
-import java.net.URL;
-
-/**
- * The deployer interface for JCA/Fungal
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- */
-public interface CloneableDeployer extends Deployer
-{
- /**
- * Clone the deployer
- * @return A copy of the deployer
- * @exception CloneNotSupportedException Thrown if the copy operation isn't supported
- *
- */
- public Deployer clone() throws CloneNotSupportedException;
-}
Copied: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/deployers/CloneableDeployer.java (from rev 97165, projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployers/CloneableDeployer.java)
===================================================================
--- projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/deployers/CloneableDeployer.java (rev 0)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/deployers/CloneableDeployer.java 2009-11-30 14:38:21 UTC (rev 97166)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This 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.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.fungal.deployers;
+
+/**
+ * The deployer interface for JCA/Fungal
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public interface CloneableDeployer extends Cloneable, Deployer
+{
+ /**
+ * Clone the deployer
+ * @return A copy of the deployer
+ * @exception CloneNotSupportedException Thrown if the copy operation isn't supported
+ *
+ */
+ public Deployer clone() throws CloneNotSupportedException;
+}
Deleted: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java 2009-11-30 11:05:54 UTC (rev 97161)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java 2009-11-30 14:38:21 UTC (rev 97166)
@@ -1,867 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This 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.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.jca.fungal.impl;
-
-import org.jboss.jca.fungal.deployers.CloneableDeployer;
-import org.jboss.jca.fungal.deployers.DeployException;
-import org.jboss.jca.fungal.deployers.Deployer;
-import org.jboss.jca.fungal.deployers.Deployment;
-import org.jboss.jca.fungal.deployment.BeanType;
-import org.jboss.jca.fungal.deployment.ConstructorType;
-import org.jboss.jca.fungal.deployment.DependsType;
-import org.jboss.jca.fungal.deployment.InjectType;
-import org.jboss.jca.fungal.deployment.PropertyType;
-import org.jboss.jca.fungal.deployment.Unmarshaller;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.InetAddress;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Future;
-
-/**
- * The deployment deployer (deploys .xml files)
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- */
-public class DeploymentDeployer implements CloneableDeployer
-{
- /** The kernel */
- private KernelImpl kernel;
-
- /** Logging */
- private static Object logging;
-
- /**
- * Constructor
- * @param kernel The kernel
- */
- public DeploymentDeployer(KernelImpl kernel)
- {
- if (kernel == null)
- throw new IllegalArgumentException("Kernel is null");
-
- this.kernel = kernel;
-
- if (logging == null)
- initLogging(kernel.getKernelClassLoader());
- }
-
- /**
- * Deploy
- * @param url The URL
- * @param parent The parent classloader
- * @return The deployment; or null if no deployment was made
- * @exception DeployException Thrown if an error occurs during deployment
- */
- public Deployment deploy(URL url, ClassLoader parent) throws DeployException
- {
- if (url == null || !url.toString().endsWith(".xml"))
- return null;
-
- DeployException deployException = null;
- try
- {
- Unmarshaller deploymentU = new Unmarshaller();
- org.jboss.jca.fungal.deployment.Deployment deployment =
- deploymentU.unmarshal(url);
-
- if (deployment != null && deployment.getBean().size() > 0)
- {
- for (BeanType bt : deployment.getBean())
- {
- kernel.setBeanStatus(bt.getName(), ServiceLifecycle.NOT_STARTED);
- }
-
- kernel.beansRegistered();
-
- List<BeanDeployer> deployers = new ArrayList<BeanDeployer>(deployment.getBean().size());
- List<String> beans = Collections.synchronizedList(new ArrayList<String>(deployment.getBean().size()));
-
- final CountDownLatch beansLatch = new CountDownLatch(deployment.getBean().size());
-
- for (BeanType bt : deployment.getBean())
- {
- BeanDeployer deployer = new BeanDeployer(bt, beans, kernel, beansLatch, parent);
- deployers.add(deployer);
-
- Future<?> result = kernel.getExecutorService().submit(deployer);
- }
-
- beansLatch.await();
-
- Iterator<BeanDeployer> it = deployers.iterator();
- while (deployException == null && it.hasNext())
- {
- BeanDeployer deployer = it.next();
- if (deployer.getDeployException() != null)
- deployException = deployer.getDeployException();
- }
-
- if (deployException == null)
- return new BeanDeployment(url, beans, kernel);
- }
- }
- catch (Throwable t)
- {
- error(t.getMessage(), t);
- throw new DeployException("Deployment " + url + " failed", t);
- }
-
- if (deployException != null)
- throw new DeployException("Deployment " + url + " failed", deployException);
-
- return null;
- }
-
- /**
- * Bean deployer
- */
- static class BeanDeployer implements Runnable
- {
- /** The bean */
- private BeanType bt;
-
- /** The bean names */
- private List<String> beans;
-
- /** The kernel */
- private KernelImpl kernel;
-
- /** The bean latch */
- private CountDownLatch beansLatch;
-
- /** The classloader */
- private ClassLoader classLoader;
-
- /** DeployException */
- private DeployException deployException;
-
- /**
- * Constructor
- * @param bt The bean
- * @param beans The list of bean names
- * @param kernel The kernel
- * @param beansLatch The beans latch
- * @param classLoader The class loader
- */
- public BeanDeployer(BeanType bt,
- List<String> beans,
- KernelImpl kernel,
- CountDownLatch beansLatch,
- ClassLoader classLoader)
- {
- this.bt = bt;
- this.beans = beans;
- this.kernel = kernel;
- this.beansLatch = beansLatch;
- this.classLoader = classLoader;
- this.deployException = null;
- }
-
- /**
- * Run
- */
- public void run()
- {
- SecurityActions.setThreadContextClassLoader(classLoader);
-
- String beanName = bt.getName();
- try
- {
- if (kernel.getBean(beanName) == null)
- {
- Set<String> dependencies = getDependencies(bt);
- int notStarted = getNotStarted(dependencies);
-
- while (notStarted > 0)
- {
- try
- {
- Thread.sleep(10);
- notStarted = getNotStarted(dependencies);
- }
- catch (InterruptedException ie)
- {
- Thread.interrupted();
- }
- }
-
- kernel.setBeanStatus(beanName, ServiceLifecycle.STARTING);
-
- Object bean = createBean(bt, classLoader);
-
- kernel.addBean(beanName, bean);
- beans.add(beanName);
-
- kernel.setBeanStatus(beanName, ServiceLifecycle.STARTED);
- }
- else
- {
- warn("Warning: A service with name " + beanName + " already exists");
- }
- }
- catch (Throwable t)
- {
- deployException = new DeployException("Installing bean " + beanName, t);
- kernel.setBeanStatus(beanName, ServiceLifecycle.ERROR);
- error("Installing bean " + beanName, t);
- }
-
- beansLatch.countDown();
- }
-
- /**
- * Get deploy exception
- * @return null if no error; otherwise the exception
- */
- public DeployException getDeployException()
- {
- return deployException;
- }
-
- /**
- * Get the depedencies for a bean
- * @paran bt The bean type
- * @return The set of dependencies; <code>null</code> if no dependencies
- */
- private Set<String> getDependencies(BeanType bt)
- {
- Set<String> result = null;
-
- List<DependsType> dts = bt.getDepends();
- if (dts.size() > 0)
- {
- result = new HashSet<String>();
- for (DependsType dt : dts)
- {
- result.add(dt.getValue());
- }
- }
-
- List<PropertyType> pts = bt.getProperty();
- if (pts.size() > 0)
- {
- if (result == null)
- result = new HashSet<String>();
-
- for (PropertyType pt : pts)
- {
- Object element = pt.getContent().get(0);
-
- if (element != null && element instanceof InjectType)
- {
- InjectType it = (InjectType)element;
- result.add(it.getBean());
-
- kernel.addBeanDependants(it.getBean(), bt.getName());
- }
- }
- }
-
- return result;
- }
-
- /**
- * Get the number of services that are not started yet
- * @paran dependencies The dependencies for a service
- * @return The number of not started services
- * @exception DeployException Thrown if an unknown dependency is found
- */
- private int getNotStarted(Set<String> dependencies) throws DeployException
- {
- if (dependencies == null || dependencies.size() == 0)
- return 0;
-
- int count = 0;
- for (String dependency : dependencies)
- {
- ServiceLifecycle dependencyStatus = kernel.getBeanStatus(dependency);
-
- if (dependencyStatus == null && kernel.isAllBeansRegistered())
- throw new DeployException("Unknown dependency: " + dependency);
-
- if (dependencyStatus == null ||
- (dependencyStatus != ServiceLifecycle.STARTED && dependencyStatus != ServiceLifecycle.ERROR))
- count += 1;
- }
-
- return count;
- }
-
- /**
- * Create a bean
- * @param bt The bean type definition
- * @param cl The classloader
- * @return The new bean
- * @exception Throwable Thrown if an error occurs
- */
- @SuppressWarnings("unchecked")
- private Object createBean(BeanType bt, ClassLoader cl) throws Throwable
- {
- Class<?> clz = null;
- Object instance = null;
-
- if (bt.getClazz() != null)
- {
- clz = Class.forName(bt.getClazz(), true, cl);
- instance = clz.newInstance();
- }
- else
- {
- ConstructorType ct = bt.getConstructor();
- Class factoryClass = Class.forName(ct.getFactoryClass(), true, cl);
- Method factoryMethod = null;
- Object[] args = null;
-
- if (ct.getParameter().size() == 0)
- {
- factoryMethod = factoryClass.getMethod(ct.getFactoryMethod(), (Class[])null);
- }
- else
- {
- Method[] factoryMethods = factoryClass.getMethods();
-
- List<Method> candidates = new ArrayList<Method>();
-
- for (Method m : factoryMethods)
- {
- if (ct.getFactoryMethod().equals(m.getName()))
- {
- if (ct.getParameter().size() == m.getParameterTypes().length)
- {
- boolean include = true;
- for (int i = 0; include && i < m.getParameterTypes().length; i++)
- {
- Class<?> parameterClass = m.getParameterTypes()[i];
-
- if (!(parameterClass.equals(String.class) ||
- parameterClass.equals(byte.class) || parameterClass.equals(Byte.class) ||
- parameterClass.equals(short.class) || parameterClass.equals(Short.class) ||
- parameterClass.equals(int.class) || parameterClass.equals(Integer.class) ||
- parameterClass.equals(long.class) || parameterClass.equals(Long.class) ||
- parameterClass.equals(float.class) || parameterClass.equals(Float.class) ||
- parameterClass.equals(double.class) || parameterClass.equals(Double.class) ||
- parameterClass.equals(boolean.class) || parameterClass.equals(Boolean.class) ||
- parameterClass.equals(char.class) || parameterClass.equals(Character.class) ||
- parameterClass.equals(InetAddress.class)))
- {
- include = false;
- }
- }
-
- if (include)
- candidates.add(m);
- }
- }
- }
-
- if (candidates.size() == 1)
- {
- factoryMethod = candidates.get(0);
- args = new Object[ct.getParameter().size()];
- for (int i = 0; i < ct.getParameter().size(); i++)
- {
- args[i] = getValue(ct.getParameter().get(i).getValue(), factoryMethod.getParameterTypes()[i]);
- }
- }
- else
- {
- boolean found = false;
- Iterator<Method> it = candidates.iterator();
- while (!found && it.hasNext())
- {
- try
- {
- Method m = it.next();
- args = new Object[ct.getParameter().size()];
-
- for (int i = 0; i < ct.getParameter().size(); i++)
- {
- args[i] =
- getValue(ct.getParameter().get(i).getValue(), factoryMethod.getParameterTypes()[i]);
- }
-
- factoryMethod = m;
- found = true;
- }
- catch (Throwable t)
- {
- // ok - not this one...
- }
- }
- }
- }
-
- instance = factoryMethod.invoke((Object)null, args);
- clz = instance.getClass();
- }
-
- if (bt.getProperty() != null)
- {
- for (PropertyType pt : bt.getProperty())
- {
- setBeanProperty(instance, pt, cl);
- }
- }
-
- try
- {
- Method createMethod = clz.getMethod("create", (Class[])null);
- createMethod.invoke(instance, (Object[])null);
- }
- catch (NoSuchMethodException nsme)
- {
- // No create method
- }
- catch (InvocationTargetException ite)
- {
- throw ite.getTargetException();
- }
-
- try
- {
- Method startMethod = clz.getMethod("start", (Class[])null);
- startMethod.invoke(instance, (Object[])null);
- }
- catch (NoSuchMethodException nsme)
- {
- // No start method
- }
- catch (InvocationTargetException ite)
- {
- throw ite.getTargetException();
- }
-
- // Register deployer
- if (instance instanceof Deployer)
- {
- ((MainDeployerImpl)kernel.getMainDeployer()).addDeployer((Deployer)instance);
- }
-
- return instance;
- }
-
- /**
- * Get a value from a string
- * @param s The string representation
- * @param clz The class
- * @return The value
- * @exception Exception If the string cant be converted
- */
- private Object getValue(String s, Class<?> clz) throws Exception
- {
- if (clz.equals(String.class))
- {
- return s;
- }
- else if (clz.equals(byte.class) || clz.equals(Byte.class))
- {
- return Byte.valueOf(s);
- }
- else if (clz.equals(short.class) || clz.equals(Short.class))
- {
- return Short.valueOf(s);
- }
- else if (clz.equals(int.class) || clz.equals(Integer.class))
- {
- return Integer.valueOf(s);
- }
- else if (clz.equals(long.class) || clz.equals(Long.class))
- {
- return Long.valueOf(s);
- }
- else if (clz.equals(float.class) || clz.equals(Float.class))
- {
- return Float.valueOf(s);
- }
- else if (clz.equals(double.class) || clz.equals(Double.class))
- {
- return Double.valueOf(s);
- }
- else if (clz.equals(boolean.class) || clz.equals(Boolean.class))
- {
- return Boolean.valueOf(s);
- }
- else if (clz.equals(char.class) || clz.equals(Character.class))
- {
- return Character.valueOf(s.charAt(0));
- }
- else if (clz.equals(InetAddress.class))
- {
- return InetAddress.getByName(s);
- }
-
- throw new Exception("Unknown class " + clz.getName() + " for " + s);
- }
-
- /**
- * Set a property on an object instance
- * @param instance The object instance
- * @param pt The property type definition
- * @param cl The classloader
- * @exception Exception Thrown if an error occurs
- */
- private void setBeanProperty(Object instance, PropertyType pt, ClassLoader cl) throws Exception
- {
- String name = "set" + pt.getName().substring(0, 1).toUpperCase(Locale.US) + pt.getName().substring(1);
- Method m = null;
-
- if (pt.getClazz() == null)
- {
- Method[] ms = instance.getClass().getMethods();
- if (ms != null)
- {
- boolean found = false;
-
- for (int i = 0; !found && i < ms.length; i++)
- {
- if (ms[i].getName().equals(name) &&
- ms[i].getParameterTypes() != null &&
- ms[i].getParameterTypes().length == 1)
- {
- m = ms[i];
- found = true;
- }
- }
- }
- }
- else
- {
- Class clz = Class.forName(pt.getClazz(), true, cl);
- m = instance.getClass().getMethod(name, clz);
- }
-
- if (m == null)
- throw new Exception("Property " + pt.getName() + " not found on " + instance.getClass().getName());
-
- Class parameterClass = m.getParameterTypes()[0];
-
- Object parameterValue = null;
- Object element = pt.getContent().get(0);
-
- if (element == null)
- element = "";
-
- if (element instanceof InjectType)
- {
- InjectType it = (InjectType)element;
-
- Object injectionObject = kernel.getBean(it.getBean());
-
- if (injectionObject == null)
- throw new Exception("Injection depedency " + it.getBean() + " not found");
-
- if (it.getProperty() != null)
- {
- Method method = null;
- try
- {
- String getMethodName = "get" +
- it.getProperty().substring(0, 1).toUpperCase(Locale.US) + it.getProperty().substring(1);
- method = injectionObject.getClass().getMethod(getMethodName, (Class[])null);
- }
- catch (NoSuchMethodException nsme)
- {
- String isMethodName = "is" +
- it.getProperty().substring(0, 1).toUpperCase(Locale.US) + it.getProperty().substring(1);
- method = injectionObject.getClass().getMethod(isMethodName, (Class[])null);
- }
-
- parameterValue = method.invoke(injectionObject, (Object[])null);
- }
- else
- {
- parameterValue = injectionObject;
- }
- }
- else
- {
- if (parameterClass.equals(String.class))
- {
- parameterValue = getSubstitutionValue((String)element);
- }
- else if (parameterClass.equals(byte.class) || parameterClass.equals(Byte.class))
- {
- parameterValue = Byte.valueOf(getSubstitutionValue((String)element));
- }
- else if (parameterClass.equals(short.class) || parameterClass.equals(Short.class))
- {
- parameterValue = Short.valueOf(getSubstitutionValue((String)element));
- }
- else if (parameterClass.equals(int.class) || parameterClass.equals(Integer.class))
- {
- parameterValue = Integer.valueOf(getSubstitutionValue((String)element));
- }
- else if (parameterClass.equals(long.class) || parameterClass.equals(Long.class))
- {
- parameterValue = Long.valueOf(getSubstitutionValue((String)element));
- }
- else if (parameterClass.equals(float.class) || parameterClass.equals(Float.class))
- {
- parameterValue = Float.valueOf(getSubstitutionValue((String)element));
- }
- else if (parameterClass.equals(double.class) || parameterClass.equals(Double.class))
- {
- parameterValue = Double.valueOf(getSubstitutionValue((String)element));
- }
- else if (parameterClass.equals(boolean.class) || parameterClass.equals(Boolean.class))
- {
- parameterValue = Boolean.valueOf(getSubstitutionValue((String)element));
- }
- else if (parameterClass.equals(char.class) || parameterClass.equals(Character.class))
- {
- parameterValue = Character.valueOf((getSubstitutionValue((String)element)).charAt(0));
- }
- else if (parameterClass.equals(InetAddress.class))
- {
- parameterValue = InetAddress.getByName(getSubstitutionValue((String)element));
- }
- }
-
- if (parameterValue == null)
- throw new Exception("No parameter value assigned for class " + parameterClass.getName() +
- " value " + element);
-
- m.invoke(instance, parameterValue);
- }
-
- /**
- * System property substitution
- * @param input The input string
- * @return The output
- */
- private String getSubstitutionValue(String input)
- {
- if (input == null || input.trim().equals(""))
- return input;
-
- if (input.indexOf("${") != -1)
- {
- int from = input.indexOf("${");
- int to = input.indexOf("}");
- int dv = input.indexOf(":");
-
- String systemProperty = "";
- String defaultValue = "";
- if (dv == -1)
- {
- systemProperty = SecurityActions.getSystemProperty(input.substring(from + 2, to));
- }
- else
- {
- systemProperty = SecurityActions.getSystemProperty(input.substring(from + 2, dv));
- defaultValue = input.substring(dv + 1, to);
- }
- String prefix = "";
- String postfix = "";
-
- if (from != 0)
- {
- prefix = input.substring(0, from);
- }
-
- if (to + 1 < input.length() - 1)
- {
- postfix = input.substring(to + 1);
- }
-
- if (systemProperty != null && !systemProperty.trim().equals(""))
- {
- return prefix + systemProperty + postfix;
- }
- else if (defaultValue != null && !defaultValue.trim().equals(""))
- {
- return prefix + defaultValue + postfix;
- }
- }
- return input;
- }
- }
-
- /**
- * Init logging
- */
- @SuppressWarnings("unchecked")
- private static void initLogging(ClassLoader cl)
- {
- try
- {
- Class clz = Class.forName("org.jboss.logging.Logger", true, cl);
-
- Method mGetLogger = clz.getMethod("getLogger", String.class);
-
- logging = mGetLogger.invoke((Object)null, new Object[] {"org.jboss.jca.fungal.impl.DeploymentDeployer"});
- }
- catch (Throwable t)
- {
- // Nothing we can do
- }
- }
-
- /**
- * Logging: ERROR
- * @param s The string
- * @param t The throwable
- */
- @SuppressWarnings("unchecked")
- private static void error(String s, Throwable t)
- {
- if (logging != null)
- {
- try
- {
- Class clz = logging.getClass();
- Method mError = clz.getMethod("error", Object.class, Throwable.class);
- mError.invoke(logging, new Object[] {s, t});
- }
- catch (Throwable th)
- {
- // Nothing we can do
- }
- }
- else
- {
- System.out.println(s);
- t.printStackTrace(System.out);
- }
- }
-
- /**
- * Logging: WARN
- * @param s The string
- */
- @SuppressWarnings("unchecked")
- private static void warn(String s)
- {
- if (logging != null)
- {
- try
- {
- Class clz = logging.getClass();
- Method mWarn = clz.getMethod("warn", Object.class);
- mWarn.invoke(logging, new Object[] {s});
- }
- catch (Throwable t)
- {
- // Nothing we can do
- }
- }
- else
- {
- System.out.println(s);
- }
- }
-
- /**
- * Logging: INFO
- * @param s The string
- */
- @SuppressWarnings("unchecked")
- private static void info(String s)
- {
- if (logging != null)
- {
- try
- {
- Class clz = logging.getClass();
- Method mInfo = clz.getMethod("info", Object.class);
- mInfo.invoke(logging, new Object[] {s});
- }
- catch (Throwable t)
- {
- // Nothing we can do
- }
- }
- else
- {
- System.out.println(s);
- }
- }
-
- /**
- * Logging: Is DEBUG enabled
- * @return True if debug is enabled; otherwise false
- */
- @SuppressWarnings("unchecked")
- private static boolean isDebugEnabled()
- {
- if (logging != null)
- {
- try
- {
- Class clz = logging.getClass();
- Method mIsDebugEnabled = clz.getMethod("isDebugEnabled", (Class[])null);
- return ((Boolean)mIsDebugEnabled.invoke(logging, (Object[])null)).booleanValue();
- }
- catch (Throwable t)
- {
- // Nothing we can do
- }
- }
- return true;
- }
-
- /**
- * Logging: DEBUG
- * @param s The string
- */
- @SuppressWarnings("unchecked")
- private static void debug(String s)
- {
- if (logging != null)
- {
- try
- {
- Class clz = logging.getClass();
- Method mDebug = clz.getMethod("debug", Object.class);
- mDebug.invoke(logging, new Object[] {s});
- }
- catch (Throwable t)
- {
- // Nothing we can do
- }
- }
- else
- {
- System.out.println(s);
- }
- }
-
- /**
- * Clone
- * @return The copy of the object
- * @exception CloneNotSupportedException Thrown if a copy can't be created
- */
- public Deployer clone() throws CloneNotSupportedException
- {
- return new DeploymentDeployer(kernel);
- }
-}
Copied: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java (from rev 97165, projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java)
===================================================================
--- projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java (rev 0)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java 2009-11-30 14:38:21 UTC (rev 97166)
@@ -0,0 +1,867 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This 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.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.fungal.impl;
+
+import org.jboss.jca.fungal.deployers.CloneableDeployer;
+import org.jboss.jca.fungal.deployers.DeployException;
+import org.jboss.jca.fungal.deployers.Deployer;
+import org.jboss.jca.fungal.deployers.Deployment;
+import org.jboss.jca.fungal.deployment.BeanType;
+import org.jboss.jca.fungal.deployment.ConstructorType;
+import org.jboss.jca.fungal.deployment.DependsType;
+import org.jboss.jca.fungal.deployment.InjectType;
+import org.jboss.jca.fungal.deployment.PropertyType;
+import org.jboss.jca.fungal.deployment.Unmarshaller;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.InetAddress;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Future;
+
+/**
+ * The deployment deployer (deploys .xml files)
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public final class DeploymentDeployer implements CloneableDeployer
+{
+ /** The kernel */
+ private KernelImpl kernel;
+
+ /** Logging */
+ private static Object logging;
+
+ /**
+ * Constructor
+ * @param kernel The kernel
+ */
+ public DeploymentDeployer(KernelImpl kernel)
+ {
+ if (kernel == null)
+ throw new IllegalArgumentException("Kernel is null");
+
+ this.kernel = kernel;
+
+ if (logging == null)
+ initLogging(kernel.getKernelClassLoader());
+ }
+
+ /**
+ * Deploy
+ * @param url The URL
+ * @param parent The parent classloader
+ * @return The deployment; or null if no deployment was made
+ * @exception DeployException Thrown if an error occurs during deployment
+ */
+ public Deployment deploy(URL url, ClassLoader parent) throws DeployException
+ {
+ if (url == null || !url.toString().endsWith(".xml"))
+ return null;
+
+ DeployException deployException = null;
+ try
+ {
+ Unmarshaller deploymentU = new Unmarshaller();
+ org.jboss.jca.fungal.deployment.Deployment deployment =
+ deploymentU.unmarshal(url);
+
+ if (deployment != null && deployment.getBean().size() > 0)
+ {
+ for (BeanType bt : deployment.getBean())
+ {
+ kernel.setBeanStatus(bt.getName(), ServiceLifecycle.NOT_STARTED);
+ }
+
+ kernel.beansRegistered();
+
+ List<BeanDeployer> deployers = new ArrayList<BeanDeployer>(deployment.getBean().size());
+ List<String> beans = Collections.synchronizedList(new ArrayList<String>(deployment.getBean().size()));
+
+ final CountDownLatch beansLatch = new CountDownLatch(deployment.getBean().size());
+
+ for (BeanType bt : deployment.getBean())
+ {
+ BeanDeployer deployer = new BeanDeployer(bt, beans, kernel, beansLatch, parent);
+ deployers.add(deployer);
+
+ Future<?> result = kernel.getExecutorService().submit(deployer);
+ }
+
+ beansLatch.await();
+
+ Iterator<BeanDeployer> it = deployers.iterator();
+ while (deployException == null && it.hasNext())
+ {
+ BeanDeployer deployer = it.next();
+ if (deployer.getDeployException() != null)
+ deployException = deployer.getDeployException();
+ }
+
+ if (deployException == null)
+ return new BeanDeployment(url, beans, kernel);
+ }
+ }
+ catch (Throwable t)
+ {
+ error(t.getMessage(), t);
+ throw new DeployException("Deployment " + url + " failed", t);
+ }
+
+ if (deployException != null)
+ throw new DeployException("Deployment " + url + " failed", deployException);
+
+ return null;
+ }
+
+ /**
+ * Bean deployer
+ */
+ static class BeanDeployer implements Runnable
+ {
+ /** The bean */
+ private BeanType bt;
+
+ /** The bean names */
+ private List<String> beans;
+
+ /** The kernel */
+ private KernelImpl kernel;
+
+ /** The bean latch */
+ private CountDownLatch beansLatch;
+
+ /** The classloader */
+ private ClassLoader classLoader;
+
+ /** DeployException */
+ private DeployException deployException;
+
+ /**
+ * Constructor
+ * @param bt The bean
+ * @param beans The list of bean names
+ * @param kernel The kernel
+ * @param beansLatch The beans latch
+ * @param classLoader The class loader
+ */
+ public BeanDeployer(BeanType bt,
+ List<String> beans,
+ KernelImpl kernel,
+ CountDownLatch beansLatch,
+ ClassLoader classLoader)
+ {
+ this.bt = bt;
+ this.beans = beans;
+ this.kernel = kernel;
+ this.beansLatch = beansLatch;
+ this.classLoader = classLoader;
+ this.deployException = null;
+ }
+
+ /**
+ * Run
+ */
+ public void run()
+ {
+ SecurityActions.setThreadContextClassLoader(classLoader);
+
+ String beanName = bt.getName();
+ try
+ {
+ if (kernel.getBean(beanName) == null)
+ {
+ Set<String> dependencies = getDependencies(bt);
+ int notStarted = getNotStarted(dependencies);
+
+ while (notStarted > 0)
+ {
+ try
+ {
+ Thread.sleep(10);
+ notStarted = getNotStarted(dependencies);
+ }
+ catch (InterruptedException ie)
+ {
+ Thread.interrupted();
+ }
+ }
+
+ kernel.setBeanStatus(beanName, ServiceLifecycle.STARTING);
+
+ Object bean = createBean(bt, classLoader);
+
+ kernel.addBean(beanName, bean);
+ beans.add(beanName);
+
+ kernel.setBeanStatus(beanName, ServiceLifecycle.STARTED);
+ }
+ else
+ {
+ warn("Warning: A service with name " + beanName + " already exists");
+ }
+ }
+ catch (Throwable t)
+ {
+ deployException = new DeployException("Installing bean " + beanName, t);
+ kernel.setBeanStatus(beanName, ServiceLifecycle.ERROR);
+ error("Installing bean " + beanName, t);
+ }
+
+ beansLatch.countDown();
+ }
+
+ /**
+ * Get deploy exception
+ * @return null if no error; otherwise the exception
+ */
+ public DeployException getDeployException()
+ {
+ return deployException;
+ }
+
+ /**
+ * Get the depedencies for a bean
+ * @paran bt The bean type
+ * @return The set of dependencies; <code>null</code> if no dependencies
+ */
+ private Set<String> getDependencies(BeanType bt)
+ {
+ Set<String> result = null;
+
+ List<DependsType> dts = bt.getDepends();
+ if (dts.size() > 0)
+ {
+ result = new HashSet<String>();
+ for (DependsType dt : dts)
+ {
+ result.add(dt.getValue());
+ }
+ }
+
+ List<PropertyType> pts = bt.getProperty();
+ if (pts.size() > 0)
+ {
+ if (result == null)
+ result = new HashSet<String>();
+
+ for (PropertyType pt : pts)
+ {
+ Object element = pt.getContent().get(0);
+
+ if (element != null && element instanceof InjectType)
+ {
+ InjectType it = (InjectType)element;
+ result.add(it.getBean());
+
+ kernel.addBeanDependants(it.getBean(), bt.getName());
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Get the number of services that are not started yet
+ * @paran dependencies The dependencies for a service
+ * @return The number of not started services
+ * @exception DeployException Thrown if an unknown dependency is found
+ */
+ private int getNotStarted(Set<String> dependencies) throws DeployException
+ {
+ if (dependencies == null || dependencies.size() == 0)
+ return 0;
+
+ int count = 0;
+ for (String dependency : dependencies)
+ {
+ ServiceLifecycle dependencyStatus = kernel.getBeanStatus(dependency);
+
+ if (dependencyStatus == null && kernel.isAllBeansRegistered())
+ throw new DeployException("Unknown dependency: " + dependency);
+
+ if (dependencyStatus == null ||
+ (dependencyStatus != ServiceLifecycle.STARTED && dependencyStatus != ServiceLifecycle.ERROR))
+ count += 1;
+ }
+
+ return count;
+ }
+
+ /**
+ * Create a bean
+ * @param bt The bean type definition
+ * @param cl The classloader
+ * @return The new bean
+ * @exception Throwable Thrown if an error occurs
+ */
+ @SuppressWarnings("unchecked")
+ private Object createBean(BeanType bt, ClassLoader cl) throws Throwable
+ {
+ Class<?> clz = null;
+ Object instance = null;
+
+ if (bt.getClazz() != null)
+ {
+ clz = Class.forName(bt.getClazz(), true, cl);
+ instance = clz.newInstance();
+ }
+ else
+ {
+ ConstructorType ct = bt.getConstructor();
+ Class factoryClass = Class.forName(ct.getFactoryClass(), true, cl);
+ Method factoryMethod = null;
+ Object[] args = null;
+
+ if (ct.getParameter().size() == 0)
+ {
+ factoryMethod = factoryClass.getMethod(ct.getFactoryMethod(), (Class[])null);
+ }
+ else
+ {
+ Method[] factoryMethods = factoryClass.getMethods();
+
+ List<Method> candidates = new ArrayList<Method>();
+
+ for (Method m : factoryMethods)
+ {
+ if (ct.getFactoryMethod().equals(m.getName()))
+ {
+ if (ct.getParameter().size() == m.getParameterTypes().length)
+ {
+ boolean include = true;
+ for (int i = 0; include && i < m.getParameterTypes().length; i++)
+ {
+ Class<?> parameterClass = m.getParameterTypes()[i];
+
+ if (!(parameterClass.equals(String.class) ||
+ parameterClass.equals(byte.class) || parameterClass.equals(Byte.class) ||
+ parameterClass.equals(short.class) || parameterClass.equals(Short.class) ||
+ parameterClass.equals(int.class) || parameterClass.equals(Integer.class) ||
+ parameterClass.equals(long.class) || parameterClass.equals(Long.class) ||
+ parameterClass.equals(float.class) || parameterClass.equals(Float.class) ||
+ parameterClass.equals(double.class) || parameterClass.equals(Double.class) ||
+ parameterClass.equals(boolean.class) || parameterClass.equals(Boolean.class) ||
+ parameterClass.equals(char.class) || parameterClass.equals(Character.class) ||
+ parameterClass.equals(InetAddress.class)))
+ {
+ include = false;
+ }
+ }
+
+ if (include)
+ candidates.add(m);
+ }
+ }
+ }
+
+ if (candidates.size() == 1)
+ {
+ factoryMethod = candidates.get(0);
+ args = new Object[ct.getParameter().size()];
+ for (int i = 0; i < ct.getParameter().size(); i++)
+ {
+ args[i] = getValue(ct.getParameter().get(i).getValue(), factoryMethod.getParameterTypes()[i]);
+ }
+ }
+ else
+ {
+ boolean found = false;
+ Iterator<Method> it = candidates.iterator();
+ while (!found && it.hasNext())
+ {
+ try
+ {
+ Method m = it.next();
+ args = new Object[ct.getParameter().size()];
+
+ for (int i = 0; i < ct.getParameter().size(); i++)
+ {
+ args[i] =
+ getValue(ct.getParameter().get(i).getValue(), factoryMethod.getParameterTypes()[i]);
+ }
+
+ factoryMethod = m;
+ found = true;
+ }
+ catch (Throwable t)
+ {
+ // ok - not this one...
+ }
+ }
+ }
+ }
+
+ instance = factoryMethod.invoke((Object)null, args);
+ clz = instance.getClass();
+ }
+
+ if (bt.getProperty() != null)
+ {
+ for (PropertyType pt : bt.getProperty())
+ {
+ setBeanProperty(instance, pt, cl);
+ }
+ }
+
+ try
+ {
+ Method createMethod = clz.getMethod("create", (Class[])null);
+ createMethod.invoke(instance, (Object[])null);
+ }
+ catch (NoSuchMethodException nsme)
+ {
+ // No create method
+ }
+ catch (InvocationTargetException ite)
+ {
+ throw ite.getTargetException();
+ }
+
+ try
+ {
+ Method startMethod = clz.getMethod("start", (Class[])null);
+ startMethod.invoke(instance, (Object[])null);
+ }
+ catch (NoSuchMethodException nsme)
+ {
+ // No start method
+ }
+ catch (InvocationTargetException ite)
+ {
+ throw ite.getTargetException();
+ }
+
+ // Register deployer
+ if (instance instanceof Deployer)
+ {
+ ((MainDeployerImpl)kernel.getMainDeployer()).addDeployer((Deployer)instance);
+ }
+
+ return instance;
+ }
+
+ /**
+ * Get a value from a string
+ * @param s The string representation
+ * @param clz The class
+ * @return The value
+ * @exception Exception If the string cant be converted
+ */
+ private Object getValue(String s, Class<?> clz) throws Exception
+ {
+ if (clz.equals(String.class))
+ {
+ return s;
+ }
+ else if (clz.equals(byte.class) || clz.equals(Byte.class))
+ {
+ return Byte.valueOf(s);
+ }
+ else if (clz.equals(short.class) || clz.equals(Short.class))
+ {
+ return Short.valueOf(s);
+ }
+ else if (clz.equals(int.class) || clz.equals(Integer.class))
+ {
+ return Integer.valueOf(s);
+ }
+ else if (clz.equals(long.class) || clz.equals(Long.class))
+ {
+ return Long.valueOf(s);
+ }
+ else if (clz.equals(float.class) || clz.equals(Float.class))
+ {
+ return Float.valueOf(s);
+ }
+ else if (clz.equals(double.class) || clz.equals(Double.class))
+ {
+ return Double.valueOf(s);
+ }
+ else if (clz.equals(boolean.class) || clz.equals(Boolean.class))
+ {
+ return Boolean.valueOf(s);
+ }
+ else if (clz.equals(char.class) || clz.equals(Character.class))
+ {
+ return Character.valueOf(s.charAt(0));
+ }
+ else if (clz.equals(InetAddress.class))
+ {
+ return InetAddress.getByName(s);
+ }
+
+ throw new Exception("Unknown class " + clz.getName() + " for " + s);
+ }
+
+ /**
+ * Set a property on an object instance
+ * @param instance The object instance
+ * @param pt The property type definition
+ * @param cl The classloader
+ * @exception Exception Thrown if an error occurs
+ */
+ private void setBeanProperty(Object instance, PropertyType pt, ClassLoader cl) throws Exception
+ {
+ String name = "set" + pt.getName().substring(0, 1).toUpperCase(Locale.US) + pt.getName().substring(1);
+ Method m = null;
+
+ if (pt.getClazz() == null)
+ {
+ Method[] ms = instance.getClass().getMethods();
+ if (ms != null)
+ {
+ boolean found = false;
+
+ for (int i = 0; !found && i < ms.length; i++)
+ {
+ if (ms[i].getName().equals(name) &&
+ ms[i].getParameterTypes() != null &&
+ ms[i].getParameterTypes().length == 1)
+ {
+ m = ms[i];
+ found = true;
+ }
+ }
+ }
+ }
+ else
+ {
+ Class clz = Class.forName(pt.getClazz(), true, cl);
+ m = instance.getClass().getMethod(name, clz);
+ }
+
+ if (m == null)
+ throw new Exception("Property " + pt.getName() + " not found on " + instance.getClass().getName());
+
+ Class parameterClass = m.getParameterTypes()[0];
+
+ Object parameterValue = null;
+ Object element = pt.getContent().get(0);
+
+ if (element == null)
+ element = "";
+
+ if (element instanceof InjectType)
+ {
+ InjectType it = (InjectType)element;
+
+ Object injectionObject = kernel.getBean(it.getBean());
+
+ if (injectionObject == null)
+ throw new Exception("Injection depedency " + it.getBean() + " not found");
+
+ if (it.getProperty() != null)
+ {
+ Method method = null;
+ try
+ {
+ String getMethodName = "get" +
+ it.getProperty().substring(0, 1).toUpperCase(Locale.US) + it.getProperty().substring(1);
+ method = injectionObject.getClass().getMethod(getMethodName, (Class[])null);
+ }
+ catch (NoSuchMethodException nsme)
+ {
+ String isMethodName = "is" +
+ it.getProperty().substring(0, 1).toUpperCase(Locale.US) + it.getProperty().substring(1);
+ method = injectionObject.getClass().getMethod(isMethodName, (Class[])null);
+ }
+
+ parameterValue = method.invoke(injectionObject, (Object[])null);
+ }
+ else
+ {
+ parameterValue = injectionObject;
+ }
+ }
+ else
+ {
+ if (parameterClass.equals(String.class))
+ {
+ parameterValue = getSubstitutionValue((String)element);
+ }
+ else if (parameterClass.equals(byte.class) || parameterClass.equals(Byte.class))
+ {
+ parameterValue = Byte.valueOf(getSubstitutionValue((String)element));
+ }
+ else if (parameterClass.equals(short.class) || parameterClass.equals(Short.class))
+ {
+ parameterValue = Short.valueOf(getSubstitutionValue((String)element));
+ }
+ else if (parameterClass.equals(int.class) || parameterClass.equals(Integer.class))
+ {
+ parameterValue = Integer.valueOf(getSubstitutionValue((String)element));
+ }
+ else if (parameterClass.equals(long.class) || parameterClass.equals(Long.class))
+ {
+ parameterValue = Long.valueOf(getSubstitutionValue((String)element));
+ }
+ else if (parameterClass.equals(float.class) || parameterClass.equals(Float.class))
+ {
+ parameterValue = Float.valueOf(getSubstitutionValue((String)element));
+ }
+ else if (parameterClass.equals(double.class) || parameterClass.equals(Double.class))
+ {
+ parameterValue = Double.valueOf(getSubstitutionValue((String)element));
+ }
+ else if (parameterClass.equals(boolean.class) || parameterClass.equals(Boolean.class))
+ {
+ parameterValue = Boolean.valueOf(getSubstitutionValue((String)element));
+ }
+ else if (parameterClass.equals(char.class) || parameterClass.equals(Character.class))
+ {
+ parameterValue = Character.valueOf((getSubstitutionValue((String)element)).charAt(0));
+ }
+ else if (parameterClass.equals(InetAddress.class))
+ {
+ parameterValue = InetAddress.getByName(getSubstitutionValue((String)element));
+ }
+ }
+
+ if (parameterValue == null)
+ throw new Exception("No parameter value assigned for class " + parameterClass.getName() +
+ " value " + element);
+
+ m.invoke(instance, parameterValue);
+ }
+
+ /**
+ * System property substitution
+ * @param input The input string
+ * @return The output
+ */
+ private String getSubstitutionValue(String input)
+ {
+ if (input == null || input.trim().equals(""))
+ return input;
+
+ if (input.indexOf("${") != -1)
+ {
+ int from = input.indexOf("${");
+ int to = input.indexOf("}");
+ int dv = input.indexOf(":");
+
+ String systemProperty = "";
+ String defaultValue = "";
+ if (dv == -1)
+ {
+ systemProperty = SecurityActions.getSystemProperty(input.substring(from + 2, to));
+ }
+ else
+ {
+ systemProperty = SecurityActions.getSystemProperty(input.substring(from + 2, dv));
+ defaultValue = input.substring(dv + 1, to);
+ }
+ String prefix = "";
+ String postfix = "";
+
+ if (from != 0)
+ {
+ prefix = input.substring(0, from);
+ }
+
+ if (to + 1 < input.length() - 1)
+ {
+ postfix = input.substring(to + 1);
+ }
+
+ if (systemProperty != null && !systemProperty.trim().equals(""))
+ {
+ return prefix + systemProperty + postfix;
+ }
+ else if (defaultValue != null && !defaultValue.trim().equals(""))
+ {
+ return prefix + defaultValue + postfix;
+ }
+ }
+ return input;
+ }
+ }
+
+ /**
+ * Init logging
+ */
+ @SuppressWarnings("unchecked")
+ private static void initLogging(ClassLoader cl)
+ {
+ try
+ {
+ Class clz = Class.forName("org.jboss.logging.Logger", true, cl);
+
+ Method mGetLogger = clz.getMethod("getLogger", String.class);
+
+ logging = mGetLogger.invoke((Object)null, new Object[] {"org.jboss.jca.fungal.impl.DeploymentDeployer"});
+ }
+ catch (Throwable t)
+ {
+ // Nothing we can do
+ }
+ }
+
+ /**
+ * Logging: ERROR
+ * @param s The string
+ * @param t The throwable
+ */
+ @SuppressWarnings("unchecked")
+ private static void error(String s, Throwable t)
+ {
+ if (logging != null)
+ {
+ try
+ {
+ Class clz = logging.getClass();
+ Method mError = clz.getMethod("error", Object.class, Throwable.class);
+ mError.invoke(logging, new Object[] {s, t});
+ }
+ catch (Throwable th)
+ {
+ // Nothing we can do
+ }
+ }
+ else
+ {
+ System.out.println(s);
+ t.printStackTrace(System.out);
+ }
+ }
+
+ /**
+ * Logging: WARN
+ * @param s The string
+ */
+ @SuppressWarnings("unchecked")
+ private static void warn(String s)
+ {
+ if (logging != null)
+ {
+ try
+ {
+ Class clz = logging.getClass();
+ Method mWarn = clz.getMethod("warn", Object.class);
+ mWarn.invoke(logging, new Object[] {s});
+ }
+ catch (Throwable t)
+ {
+ // Nothing we can do
+ }
+ }
+ else
+ {
+ System.out.println(s);
+ }
+ }
+
+ /**
+ * Logging: INFO
+ * @param s The string
+ */
+ @SuppressWarnings("unchecked")
+ private static void info(String s)
+ {
+ if (logging != null)
+ {
+ try
+ {
+ Class clz = logging.getClass();
+ Method mInfo = clz.getMethod("info", Object.class);
+ mInfo.invoke(logging, new Object[] {s});
+ }
+ catch (Throwable t)
+ {
+ // Nothing we can do
+ }
+ }
+ else
+ {
+ System.out.println(s);
+ }
+ }
+
+ /**
+ * Logging: Is DEBUG enabled
+ * @return True if debug is enabled; otherwise false
+ */
+ @SuppressWarnings("unchecked")
+ private static boolean isDebugEnabled()
+ {
+ if (logging != null)
+ {
+ try
+ {
+ Class clz = logging.getClass();
+ Method mIsDebugEnabled = clz.getMethod("isDebugEnabled", (Class[])null);
+ return ((Boolean)mIsDebugEnabled.invoke(logging, (Object[])null)).booleanValue();
+ }
+ catch (Throwable t)
+ {
+ // Nothing we can do
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Logging: DEBUG
+ * @param s The string
+ */
+ @SuppressWarnings("unchecked")
+ private static void debug(String s)
+ {
+ if (logging != null)
+ {
+ try
+ {
+ Class clz = logging.getClass();
+ Method mDebug = clz.getMethod("debug", Object.class);
+ mDebug.invoke(logging, new Object[] {s});
+ }
+ catch (Throwable t)
+ {
+ // Nothing we can do
+ }
+ }
+ else
+ {
+ System.out.println(s);
+ }
+ }
+
+ /**
+ * Clone
+ * @return The copy of the object
+ * @exception CloneNotSupportedException Thrown if a copy can't be created
+ */
+ public Deployer clone() throws CloneNotSupportedException
+ {
+ return new DeploymentDeployer(kernel);
+ }
+}
Deleted: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/KernelImpl.java
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/KernelImpl.java 2009-11-30 11:05:54 UTC (rev 97161)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/KernelImpl.java 2009-11-30 14:38:21 UTC (rev 97166)
@@ -1,913 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This 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.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.jca.fungal.impl;
-
-import org.jboss.jca.fungal.api.Kernel;
-import org.jboss.jca.fungal.api.MainDeployer;
-import org.jboss.jca.fungal.deployers.Deployment;
-import org.jboss.jca.fungal.impl.remote.CommunicationServer;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-import java.util.concurrent.SynchronousQueue;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.ObjectName;
-
-/**
- * The kernel implementation for JBoss JCA/Fungal
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- */
-public class KernelImpl implements Kernel
-{
- /** Kernel configuration */
- private KernelConfiguration kernelConfiguration;
-
- /** Deployments */
- private List<Deployment> deployments = Collections.synchronizedList(new LinkedList<Deployment>());
-
- /** Beans */
- private ConcurrentMap<String, Object> beans = new ConcurrentHashMap<String, Object>();
-
- /** Bean status */
- private ConcurrentMap<String, ServiceLifecycle> beanStatus = new ConcurrentHashMap<String, ServiceLifecycle>();
-
- /** Bean dependants */
- private ConcurrentMap<String, Set<String>> beanDependants = new ConcurrentHashMap<String, Set<String>>();
-
- /** Bean deployments */
- private AtomicInteger beanDeployments;
-
- /** Kernel thread pool */
- private ThreadPoolExecutor threadPoolExecutor;
-
- /** The old class loader */
- private ClassLoader oldClassLoader;
-
- /** Kernel class loader */
- private KernelClassLoader kernelClassLoader;
-
- /** Main deployer */
- private MainDeployerImpl mainDeployer;
-
- /** MBeanServer */
- private MBeanServer mbeanServer;
-
- /** Communition server */
- private CommunicationServer remote;
-
- /** Temporary environment */
- private boolean temporaryEnvironment;
-
- /** Logging */
- private Object logging;
-
- /**
- * Constructor
- * @param kc The kernel configuration
- */
- public KernelImpl(KernelConfiguration kc)
- {
- this.kernelConfiguration = kc;
- this.beanDeployments = new AtomicInteger(0);
- this.temporaryEnvironment = false;
- }
-
- /**
- * Get the MBeanServer for the kernel
- * @return The MBeanServer instance
- */
- public MBeanServer getMBeanServer()
- {
- return mbeanServer;
- }
-
- /**
- * Startup
- * @exception Throwable Thrown if an error occurs
- */
- public void startup() throws Throwable
- {
- ThreadGroup tg = kernelConfiguration.getThreadGroup();
- if (tg == null)
- tg = new ThreadGroup("jboss");
-
- BlockingQueue<Runnable> threadPoolQueue = new SynchronousQueue<Runnable>(true);
- ThreadFactory tf = new FungalThreadFactory(tg);
-
- threadPoolExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), Integer.MAX_VALUE,
- 60, TimeUnit.SECONDS,
- threadPoolQueue,
- tf);
-
- threadPoolExecutor.allowCoreThreadTimeOut(true);
- threadPoolExecutor.prestartAllCoreThreads();
-
- File root = null;
-
- if (kernelConfiguration.getHome() != null)
- {
- root = new File(kernelConfiguration.getHome().toURI());
- SecurityActions.setSystemProperty("jboss.jca.home", root.getAbsolutePath());
- }
- else
- {
- File tmp = new File(SecurityActions.getSystemProperty("java.io.tmpdir"));
- root = new File(tmp, "jboss-jca");
-
- if (root.exists())
- {
- recursiveDelete(root);
- }
-
- if (!root.mkdirs())
- throw new IOException("Could not create directory " + root.getAbsolutePath());
-
- SecurityActions.setSystemProperty("jboss.jca.home", root.getAbsolutePath());
-
- temporaryEnvironment = true;
- }
-
- File libDirectory = null;
- File configDirectory = null;
- File deployDirectory = null;
-
- if (root != null && root.exists())
- {
- libDirectory = new File(root, File.separator + "lib" + File.separator);
- configDirectory = new File(root, File.separator + "config" + File.separator);
- deployDirectory = new File(root, File.separator + "deploy" + File.separator);
- }
-
- oldClassLoader = SecurityActions.getThreadContextClassLoader();
-
- URL[] libUrls = getUrls(libDirectory);
- URL[] confUrls = getUrls(configDirectory);
-
- URL[] urls = mergeUrls(libUrls, confUrls);
-
- kernelClassLoader = SecurityActions.createKernelClassLoader(urls, oldClassLoader);
- SecurityActions.setThreadContextClassLoader(kernelClassLoader);
-
- SecurityActions.setSystemProperty("xb.builder.useUnorderedSequence", "true");
- SecurityActions.setSystemProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");
- SecurityActions.setSystemProperty("javax.xml.stream.XMLInputFactory",
- "com.sun.xml.internal.stream.XMLInputFactoryImpl");
-
- if (kernelConfiguration.getBindAddress() != null)
- SecurityActions.setSystemProperty("jboss.jca.bindaddress", kernelConfiguration.getBindAddress().trim());
-
- // Init logging
- initLogging(kernelClassLoader);
-
- // Create MBeanServer
- mbeanServer = MBeanServerFactory.createMBeanServer("jboss.jca");
-
- // Main deployer
- mainDeployer = new MainDeployerImpl(this);
- ObjectName mainDeployerObjectName = new ObjectName("jboss.jca:name=MainDeployer");
- mbeanServer.registerMBean(mainDeployer, mainDeployerObjectName);
-
- // Add the deployment deployer
- mainDeployer.addDeployer(new DeploymentDeployer(this));
-
- // Add the kernel bean reference
- addBean("Kernel", this);
- setBeanStatus("Kernel", ServiceLifecycle.STARTED);
-
- // Start all URLs defined in bootstrap.xml
- if (configDirectory != null && configDirectory.exists() && configDirectory.isDirectory())
- {
- File bootstrapXml = new File(configDirectory, "bootstrap.xml");
-
- if (bootstrapXml != null && bootstrapXml.exists())
- {
- org.jboss.jca.fungal.bootstrap.Unmarshaller bootstrapU =
- new org.jboss.jca.fungal.bootstrap.Unmarshaller();
- org.jboss.jca.fungal.bootstrap.Bootstrap bootstrap = bootstrapU.unmarshal(bootstrapXml.toURI().toURL());
-
- // Bootstrap urls
- if (bootstrap != null)
- {
- beanDeployments = new AtomicInteger(bootstrap.getUrl().size());
-
- List<URL> bootstrapUrls = new ArrayList<URL>(bootstrap.getUrl().size());
-
- for (String url : bootstrap.getUrl())
- {
- URL fullPath = new URL(configDirectory.toURI().toURL().toExternalForm() + url);
- bootstrapUrls.add(fullPath);
- }
-
- deployUrls(bootstrapUrls.toArray(new URL[bootstrapUrls.size()]));
- }
- }
- }
-
- // Deploy all files in deploy/
- if (deployDirectory != null && deployDirectory.exists() && deployDirectory.isDirectory())
- {
- File[] files = deployDirectory.listFiles();
-
- if (files != null)
- {
- int counter = 0;
- for (File f : files)
- {
- if (f.toURI().toURL().toString().endsWith(".xml"))
- counter++;
- }
-
- beanDeployments = new AtomicInteger(counter);
-
- for (File f : files)
- {
- deployUrls(new URL[] {f.toURI().toURL()});
- }
- }
- }
-
- // Remote MBeanServer access
- if (kernelConfiguration.isRemoteAccess())
- {
- remote = new CommunicationServer(this,
- kernelConfiguration.getBindAddress(),
- kernelConfiguration.getRemotePort());
- Future<?> f = threadPoolExecutor.submit(remote);
- }
- }
-
- /**
- * Deploy URLs
- * @param urls The URLs
- */
- private void deployUrls(URL[] urls)
- {
- if (urls != null && urls.length > 0)
- {
- try
- {
- List<UnitDeployer> unitDeployers = new ArrayList<UnitDeployer>(urls.length);
-
- final CountDownLatch unitLatch = new CountDownLatch(urls.length);
-
- for (URL url : urls)
- {
- try
- {
- if (isDebugEnabled())
- debug("URL=" + url.toString());
-
- MainDeployerImpl deployer = (MainDeployerImpl)mainDeployer.clone();
- UnitDeployer unitDeployer = new UnitDeployer(url, deployer, kernelClassLoader, unitLatch);
- unitDeployers.add(unitDeployer);
-
- getExecutorService().execute(unitDeployer);
- }
- catch (Throwable deployThrowable)
- {
- error(deployThrowable.getMessage(), deployThrowable);
- }
- }
-
- unitLatch.await();
-
- Iterator<UnitDeployer> it = unitDeployers.iterator();
- while (it.hasNext())
- {
- UnitDeployer deployer = it.next();
- if (deployer.getThrowable() != null)
- {
- Throwable t = deployer.getThrowable();
- error(t.getMessage(), t);
- }
- }
- }
- catch (Throwable t)
- {
- error(t.getMessage(), t);
- }
- }
- }
-
- /**
- * Shutdown
- * @exception Throwable Thrown if an error occurs
- */
- public void shutdown() throws Throwable
- {
- SecurityActions.setThreadContextClassLoader(kernelClassLoader);
-
- // Stop the remote connector
- if (remote != null)
- {
- remote.stop();
- }
-
- // Shutdown thread pool
- threadPoolExecutor.shutdown();
-
- // Shutdown all deployments
- List<Deployment> shutdownDeployments = new LinkedList<Deployment>(deployments);
- Collections.reverse(shutdownDeployments);
-
- for (Deployment deployment : shutdownDeployments)
- {
- shutdownDeployment(deployment);
- }
-
- // Remove kernel bean
- removeBean("Kernel");
-
- // Release MBeanServer
- MBeanServerFactory.releaseMBeanServer(mbeanServer);
-
- // Cleanup temporary environment
- if (temporaryEnvironment)
- {
- File tmp = new File(SecurityActions.getSystemProperty("java.io.tmpdir"));
- File root = new File(tmp, "jboss-jca");
-
- recursiveDelete(root);
- }
-
- // Shutdown kernel class loader
- if (kernelClassLoader != null)
- {
- try
- {
- kernelClassLoader.shutdown();
- }
- catch (IOException ioe)
- {
- // Swallow
- }
- }
-
- // Reset to the old class loader
- SecurityActions.setThreadContextClassLoader(oldClassLoader);
- }
-
- /**
- * Find a deployment unit
- * @param url The unique URL for a deployment
- * @return The deployment unit; <code>null</code> if no unit is found
- */
- Deployment findDeployment(URL url)
- {
- if (deployments != null)
- {
- for (Deployment deployment : deployments)
- {
- if (deployment.getURL().toString().equals(url.toString()))
- return deployment;
- }
- }
-
- return null;
- }
-
- /**
- * Shutdown a deployment unit
- * @param deployment The deployment unit
- * @exception Throwable If an error occurs
- */
- @SuppressWarnings("unchecked")
- void shutdownDeployment(Deployment deployment) throws Throwable
- {
- SecurityActions.setThreadContextClassLoader(kernelClassLoader);
-
- try
- {
- Method stopMethod = deployment.getClass().getMethod("stop", (Class[])null);
- stopMethod.invoke(deployment, (Object[])null);
- }
- catch (NoSuchMethodException nsme)
- {
- // No stop method
- }
- catch (InvocationTargetException ite)
- {
- throw ite.getCause();
- }
-
- try
- {
- Method destroyMethod = deployment.getClass().getMethod("destroy", (Class[])null);
- destroyMethod.invoke(deployment, (Object[])null);
- }
- catch (NoSuchMethodException nsme)
- {
- // No destroy method
- }
- catch (InvocationTargetException ite)
- {
- throw ite.getCause();
- }
-
- deployments.remove(deployment);
- }
-
- /**
- * Get the kernel class loader
- * @return The class loader
- */
- public KernelClassLoader getKernelClassLoader()
- {
- return kernelClassLoader;
- }
-
- /**
- * Get the executor service
- * @return The executor service
- */
- public ExecutorService getExecutorService()
- {
- return threadPoolExecutor;
- }
-
- /**
- * Get the bean status
- * @param name The bean name
- * @return The status
- */
- ServiceLifecycle getBeanStatus(String name)
- {
- return beanStatus.get(name);
- }
-
- /**
- * Set the bean status
- * @param name The bean name
- * @param status The status
- */
- void setBeanStatus(String name, ServiceLifecycle status)
- {
- beanStatus.put(name, status);
- }
-
- /**
- * Add a bean
- * @param name The name of the bean
- * @param bean The bean
- */
- void addBean(String name, Object bean)
- {
- beans.put(name, bean);
- }
-
- /**
- * Remove a bean
- * @param name The name of the bean
- */
- void removeBean(String name)
- {
- beans.remove(name);
- beanStatus.remove(name);
- }
-
- /**
- * Get a bean
- * @param name The name of the bean
- * @return The bean
- */
- public Object getBean(String name)
- {
- return beans.get(name);
- }
-
- /**
- * Get the set of dependants for a bean
- * @param name The name of the bean
- * @return The set of dependants; <code>null</code> if there are no dependants
- */
- Set<String> getBeanDependants(String name)
- {
- return beanDependants.get(name);
- }
-
- /**
- * Add a bean to the dependants map
- * @param from The name of the from bean
- * @param to The name of the to bean
- */
- void addBeanDependants(String from, String to)
- {
- Set<String> dependants = beanDependants.get(from);
- if (dependants == null)
- {
- Set<String> newDependants = new HashSet<String>();
- dependants = beanDependants.putIfAbsent(from, newDependants);
- if (dependants == null)
- {
- dependants = newDependants;
- }
- }
-
- dependants.add(to);
- }
-
- /**
- * Register deployment
- * @param deployment The deployment
- */
- void registerDeployment(Deployment deployment)
- {
- deployments.add(deployment);
- }
-
- /**
- * Beans registered
- */
- void beansRegistered()
- {
- beanDeployments.decrementAndGet();
- }
-
- /**
- * Is all beans registered
- * @return True if all beans have been registered; otherwise false
- */
- boolean isAllBeansRegistered()
- {
- return beanDeployments.get() <= 0;
- }
-
- /**
- * Get the main deployer
- * @return The main deployer
- */
- public MainDeployer getMainDeployer()
- {
- try
- {
- return (MainDeployer)mainDeployer.clone();
- }
- catch (CloneNotSupportedException cnse)
- {
- return mainDeployer;
- }
- }
-
- /**
- * Get the URLs for the directory and all libraries located in the directory
- * @param directrory The directory
- * @return The URLs
- * @exception MalformedURLException MalformedURLException
- * @exception IOException IOException
- */
- private URL[] getUrls(File directory) throws MalformedURLException, IOException
- {
- if (directory != null && directory.exists() && directory.isDirectory())
- {
- List<URL> list = new LinkedList<URL>();
-
- // Add directory
- list.add(directory.toURI().toURL());
-
- // Add the contents of the directory too
- File[] jars = directory.listFiles(new JarFilter());
-
- if (jars != null)
- {
- for (int j = 0; j < jars.length; j++)
- {
- list.add(jars[j].getCanonicalFile().toURI().toURL());
- }
- }
-
- return list.toArray(new URL[list.size()]);
- }
-
- return new URL[0];
- }
-
- /**
- * Merge URLs into a single array
- * @param urls The URLs
- * @return The combined list
- */
- private URL[] mergeUrls(URL[]... urls)
- {
- if (urls != null)
- {
- List<URL> list = new LinkedList<URL>();
-
- for (URL[] u : urls)
- {
- if (u != null)
- {
- for (URL url : u)
- {
- list.add(url);
- }
- }
- }
-
- return list.toArray(new URL[list.size()]);
- }
-
- return new URL[0];
- }
-
- /**
- * Recursive delete
- * @param f The file handler
- * @exception IOException Thrown if a file could not be deleted
- */
- private void recursiveDelete(File f) throws IOException
- {
- if (f != null && f.exists())
- {
- File[] files = f.listFiles();
- if (files != null)
- {
- for (int i = 0; i < files.length; i++)
- {
- if (files[i].isDirectory())
- {
- recursiveDelete(files[i]);
- }
- else
- {
- if (!files[i].delete())
- throw new IOException("Could not delete " + files[i]);
- }
- }
- }
- if (!f.delete())
- throw new IOException("Could not delete " + f);
- }
- }
-
- /**
- * Init logging
- * @param cl The classloader to load from
- */
- @SuppressWarnings("unchecked")
- private void initLogging(ClassLoader cl)
- {
- try
- {
- Class clz = Class.forName("org.jboss.logmanager.log4j.BridgeRepositorySelector", true, cl);
- Method mStart = clz.getMethod("start", (Class[])null);
-
- Object brs = clz.newInstance();
-
- logging = mStart.invoke(brs, (Object[])null);
- }
- catch (Throwable t)
- {
- // Nothing we can do
- }
-
-
- try
- {
- Class clz = Class.forName("org.jboss.logging.Logger", true, cl);
-
- Method mGetLogger = clz.getMethod("getLogger", String.class);
-
- logging = mGetLogger.invoke((Object)null, new Object[] {"org.jboss.jca.fungal.impl.KernelImpl"});
- }
- catch (Throwable t)
- {
- // Nothing we can do
- }
- }
-
- /**
- * Logging: ERROR
- * @param s The string
- * @param t The throwable
- */
- @SuppressWarnings("unchecked")
- private void error(String s, Throwable t)
- {
- if (logging != null)
- {
- try
- {
- Class clz = logging.getClass();
- Method mError = clz.getMethod("error", Object.class, Throwable.class);
- mError.invoke(logging, new Object[] {s, t});
- }
- catch (Throwable th)
- {
- // Nothing we can do
- }
- }
- else
- {
- System.out.println(s);
- t.printStackTrace(System.out);
- }
- }
-
- /**
- * Logging: WARN
- * @param s The string
- */
- @SuppressWarnings("unchecked")
- private void warn(String s)
- {
- if (logging != null)
- {
- try
- {
- Class clz = logging.getClass();
- Method mWarn = clz.getMethod("warn", Object.class);
- mWarn.invoke(logging, new Object[] {s});
- }
- catch (Throwable t)
- {
- // Nothing we can do
- }
- }
- else
- {
- System.out.println(s);
- }
- }
-
- /**
- * Logging: INFO
- * @param s The string
- */
- @SuppressWarnings("unchecked")
- private void info(String s)
- {
- if (logging != null)
- {
- try
- {
- Class clz = logging.getClass();
- Method mInfo = clz.getMethod("info", Object.class);
- mInfo.invoke(logging, new Object[] {s});
- }
- catch (Throwable t)
- {
- // Nothing we can do
- }
- }
- else
- {
- System.out.println(s);
- }
- }
-
- /**
- * Logging: Is DEBUG enabled
- * @return True if debug is enabled; otherwise false
- */
- @SuppressWarnings("unchecked")
- private boolean isDebugEnabled()
- {
- if (logging != null)
- {
- try
- {
- Class clz = logging.getClass();
- Method mIsDebugEnabled = clz.getMethod("isDebugEnabled", (Class[])null);
- return ((Boolean)mIsDebugEnabled.invoke(logging, (Object[])null)).booleanValue();
- }
- catch (Throwable t)
- {
- // Nothing we can do
- }
- }
- return true;
- }
-
- /**
- * Logging: DEBUG
- * @param s The string
- */
- @SuppressWarnings("unchecked")
- private void debug(String s)
- {
- if (logging != null)
- {
- try
- {
- Class clz = logging.getClass();
- Method mDebug = clz.getMethod("debug", Object.class);
- mDebug.invoke(logging, new Object[] {s});
- }
- catch (Throwable t)
- {
- // Nothing we can do
- }
- }
- else
- {
- System.out.println(s);
- }
- }
-
- /**
- * Unit deployer
- */
- static class UnitDeployer implements Runnable
- {
- /** Unit URL */
- private URL url;
-
- /** Main deployer */
- private MainDeployerImpl deployer;
-
- /** Class loader */
- private ClassLoader classLoader;
-
- /** Unit latch */
- private CountDownLatch unitLatch;
-
- /** Throwable */
- private Throwable throwable;
-
- /**
- * Constructor
- */
- public UnitDeployer(final URL url,
- final MainDeployerImpl deployer,
- final ClassLoader classLoader,
- final CountDownLatch unitLatch)
- {
- this.url = url;
- this.deployer = deployer;
- this.classLoader = classLoader;
- this.unitLatch = unitLatch;
- this.throwable = null;
- }
-
- /**
- * Run
- */
- public void run()
- {
- SecurityActions.setThreadContextClassLoader(classLoader);
-
- try
- {
- deployer.deploy(url, classLoader);
- }
- catch (Throwable t)
- {
- throwable = t;
- }
-
- unitLatch.countDown();
- }
-
- /**
- * Get deploy exception
- * @return null if no error; otherwise the exception
- */
- public Throwable getThrowable()
- {
- return throwable;
- }
- }
-}
Copied: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/KernelImpl.java (from rev 97162, projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/KernelImpl.java)
===================================================================
--- projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/KernelImpl.java (rev 0)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/KernelImpl.java 2009-11-30 14:38:21 UTC (rev 97166)
@@ -0,0 +1,917 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This 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.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.fungal.impl;
+
+import org.jboss.jca.fungal.api.Kernel;
+import org.jboss.jca.fungal.api.MainDeployer;
+import org.jboss.jca.fungal.deployers.Deployment;
+import org.jboss.jca.fungal.impl.remote.CommunicationServer;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+
+/**
+ * The kernel implementation for JBoss JCA/Fungal
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class KernelImpl implements Kernel
+{
+ /** Kernel configuration */
+ private KernelConfiguration kernelConfiguration;
+
+ /** Deployments */
+ private List<Deployment> deployments = Collections.synchronizedList(new LinkedList<Deployment>());
+
+ /** Beans */
+ private ConcurrentMap<String, Object> beans = new ConcurrentHashMap<String, Object>();
+
+ /** Bean status */
+ private ConcurrentMap<String, ServiceLifecycle> beanStatus = new ConcurrentHashMap<String, ServiceLifecycle>();
+
+ /** Bean dependants */
+ private ConcurrentMap<String, Set<String>> beanDependants = new ConcurrentHashMap<String, Set<String>>();
+
+ /** Bean deployments */
+ private AtomicInteger beanDeployments;
+
+ /** Kernel thread pool */
+ private ThreadPoolExecutor threadPoolExecutor;
+
+ /** The old class loader */
+ private ClassLoader oldClassLoader;
+
+ /** Kernel class loader */
+ private KernelClassLoader kernelClassLoader;
+
+ /** Main deployer */
+ private MainDeployerImpl mainDeployer;
+
+ /** MBeanServer */
+ private MBeanServer mbeanServer;
+
+ /** Communition server */
+ private CommunicationServer remote;
+
+ /** Temporary environment */
+ private boolean temporaryEnvironment;
+
+ /** Logging */
+ private Object logging;
+
+ /**
+ * Constructor
+ * @param kc The kernel configuration
+ */
+ public KernelImpl(KernelConfiguration kc)
+ {
+ this.kernelConfiguration = kc;
+ this.beanDeployments = new AtomicInteger(0);
+ this.temporaryEnvironment = false;
+ }
+
+ /**
+ * Get the MBeanServer for the kernel
+ * @return The MBeanServer instance
+ */
+ public MBeanServer getMBeanServer()
+ {
+ return mbeanServer;
+ }
+
+ /**
+ * Startup
+ * @exception Throwable Thrown if an error occurs
+ */
+ public void startup() throws Throwable
+ {
+ ThreadGroup tg = kernelConfiguration.getThreadGroup();
+ if (tg == null)
+ tg = new ThreadGroup("jboss");
+
+ BlockingQueue<Runnable> threadPoolQueue = new SynchronousQueue<Runnable>(true);
+ ThreadFactory tf = new FungalThreadFactory(tg);
+
+ threadPoolExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), Integer.MAX_VALUE,
+ 60, TimeUnit.SECONDS,
+ threadPoolQueue,
+ tf);
+
+ threadPoolExecutor.allowCoreThreadTimeOut(true);
+ threadPoolExecutor.prestartAllCoreThreads();
+
+ File root = null;
+
+ if (kernelConfiguration.getHome() != null)
+ {
+ root = new File(kernelConfiguration.getHome().toURI());
+ SecurityActions.setSystemProperty("jboss.jca.home", root.getAbsolutePath());
+ }
+ else
+ {
+ File tmp = new File(SecurityActions.getSystemProperty("java.io.tmpdir"));
+ root = new File(tmp, "jboss-jca");
+
+ if (root.exists())
+ {
+ recursiveDelete(root);
+ }
+
+ if (!root.mkdirs())
+ throw new IOException("Could not create directory " + root.getAbsolutePath());
+
+ SecurityActions.setSystemProperty("jboss.jca.home", root.getAbsolutePath());
+
+ temporaryEnvironment = true;
+ }
+
+ File libDirectory = null;
+ File configDirectory = null;
+ File deployDirectory = null;
+
+ if (root != null && root.exists())
+ {
+ libDirectory = new File(root, File.separator + "lib" + File.separator);
+ configDirectory = new File(root, File.separator + "config" + File.separator);
+ deployDirectory = new File(root, File.separator + "deploy" + File.separator);
+ }
+
+ oldClassLoader = SecurityActions.getThreadContextClassLoader();
+
+ URL[] libUrls = getUrls(libDirectory);
+ URL[] confUrls = getUrls(configDirectory);
+
+ URL[] urls = mergeUrls(libUrls, confUrls);
+
+ kernelClassLoader = SecurityActions.createKernelClassLoader(urls, oldClassLoader);
+ SecurityActions.setThreadContextClassLoader(kernelClassLoader);
+
+ SecurityActions.setSystemProperty("xb.builder.useUnorderedSequence", "true");
+ SecurityActions.setSystemProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");
+ SecurityActions.setSystemProperty("javax.xml.stream.XMLInputFactory",
+ "com.sun.xml.internal.stream.XMLInputFactoryImpl");
+
+ if (kernelConfiguration.getBindAddress() != null)
+ SecurityActions.setSystemProperty("jboss.jca.bindaddress", kernelConfiguration.getBindAddress().trim());
+
+ // Init logging
+ initLogging(kernelClassLoader);
+
+ // Create MBeanServer
+ mbeanServer = MBeanServerFactory.createMBeanServer("jboss.jca");
+
+ // Main deployer
+ mainDeployer = new MainDeployerImpl(this);
+ ObjectName mainDeployerObjectName = new ObjectName("jboss.jca:name=MainDeployer");
+ mbeanServer.registerMBean(mainDeployer, mainDeployerObjectName);
+
+ // Add the deployment deployer
+ mainDeployer.addDeployer(new DeploymentDeployer(this));
+
+ // Add the kernel bean reference
+ addBean("Kernel", this);
+ setBeanStatus("Kernel", ServiceLifecycle.STARTED);
+
+ // Start all URLs defined in bootstrap.xml
+ if (configDirectory != null && configDirectory.exists() && configDirectory.isDirectory())
+ {
+ File bootstrapXml = new File(configDirectory, "bootstrap.xml");
+
+ if (bootstrapXml != null && bootstrapXml.exists())
+ {
+ org.jboss.jca.fungal.bootstrap.Unmarshaller bootstrapU =
+ new org.jboss.jca.fungal.bootstrap.Unmarshaller();
+ org.jboss.jca.fungal.bootstrap.Bootstrap bootstrap = bootstrapU.unmarshal(bootstrapXml.toURI().toURL());
+
+ // Bootstrap urls
+ if (bootstrap != null)
+ {
+ beanDeployments = new AtomicInteger(bootstrap.getUrl().size());
+
+ List<URL> bootstrapUrls = new ArrayList<URL>(bootstrap.getUrl().size());
+
+ for (String url : bootstrap.getUrl())
+ {
+ URL fullPath = new URL(configDirectory.toURI().toURL().toExternalForm() + url);
+ bootstrapUrls.add(fullPath);
+ }
+
+ deployUrls(bootstrapUrls.toArray(new URL[bootstrapUrls.size()]));
+ }
+ }
+ }
+
+ // Deploy all files in deploy/
+ if (deployDirectory != null && deployDirectory.exists() && deployDirectory.isDirectory())
+ {
+ File[] files = deployDirectory.listFiles();
+
+ if (files != null)
+ {
+ int counter = 0;
+ for (File f : files)
+ {
+ if (f.toURI().toURL().toString().endsWith(".xml"))
+ counter++;
+ }
+
+ beanDeployments = new AtomicInteger(counter);
+
+ for (File f : files)
+ {
+ deployUrls(new URL[] {f.toURI().toURL()});
+ }
+ }
+ }
+
+ // Remote MBeanServer access
+ if (kernelConfiguration.isRemoteAccess())
+ {
+ remote = new CommunicationServer(this,
+ kernelConfiguration.getBindAddress(),
+ kernelConfiguration.getRemotePort());
+ Future<?> f = threadPoolExecutor.submit(remote);
+ }
+ }
+
+ /**
+ * Deploy URLs
+ * @param urls The URLs
+ */
+ private void deployUrls(URL[] urls)
+ {
+ if (urls != null && urls.length > 0)
+ {
+ try
+ {
+ List<UnitDeployer> unitDeployers = new ArrayList<UnitDeployer>(urls.length);
+
+ final CountDownLatch unitLatch = new CountDownLatch(urls.length);
+
+ for (URL url : urls)
+ {
+ try
+ {
+ if (isDebugEnabled())
+ debug("URL=" + url.toString());
+
+ MainDeployerImpl deployer = (MainDeployerImpl)mainDeployer.clone();
+ UnitDeployer unitDeployer = new UnitDeployer(url, deployer, kernelClassLoader, unitLatch);
+ unitDeployers.add(unitDeployer);
+
+ getExecutorService().execute(unitDeployer);
+ }
+ catch (Throwable deployThrowable)
+ {
+ error(deployThrowable.getMessage(), deployThrowable);
+ }
+ }
+
+ unitLatch.await();
+
+ Iterator<UnitDeployer> it = unitDeployers.iterator();
+ while (it.hasNext())
+ {
+ UnitDeployer deployer = it.next();
+ if (deployer.getThrowable() != null)
+ {
+ Throwable t = deployer.getThrowable();
+ error(t.getMessage(), t);
+ }
+ }
+ }
+ catch (Throwable t)
+ {
+ error(t.getMessage(), t);
+ }
+ }
+ }
+
+ /**
+ * Shutdown
+ * @exception Throwable Thrown if an error occurs
+ */
+ public void shutdown() throws Throwable
+ {
+ SecurityActions.setThreadContextClassLoader(kernelClassLoader);
+
+ // Stop the remote connector
+ if (remote != null)
+ {
+ remote.stop();
+ }
+
+ // Shutdown thread pool
+ threadPoolExecutor.shutdown();
+
+ // Shutdown all deployments
+ List<Deployment> shutdownDeployments = new LinkedList<Deployment>(deployments);
+ Collections.reverse(shutdownDeployments);
+
+ for (Deployment deployment : shutdownDeployments)
+ {
+ shutdownDeployment(deployment);
+ }
+
+ // Remove kernel bean
+ removeBean("Kernel");
+
+ // Release MBeanServer
+ MBeanServerFactory.releaseMBeanServer(mbeanServer);
+
+ // Cleanup temporary environment
+ if (temporaryEnvironment)
+ {
+ File tmp = new File(SecurityActions.getSystemProperty("java.io.tmpdir"));
+ File root = new File(tmp, "jboss-jca");
+
+ recursiveDelete(root);
+ }
+
+ // Shutdown kernel class loader
+ if (kernelClassLoader != null)
+ {
+ try
+ {
+ kernelClassLoader.shutdown();
+ }
+ catch (IOException ioe)
+ {
+ // Swallow
+ }
+ }
+
+ // Reset to the old class loader
+ SecurityActions.setThreadContextClassLoader(oldClassLoader);
+ }
+
+ /**
+ * Find a deployment unit
+ * @param url The unique URL for a deployment
+ * @return The deployment unit; <code>null</code> if no unit is found
+ */
+ Deployment findDeployment(URL url)
+ {
+ if (deployments != null)
+ {
+ for (Deployment deployment : deployments)
+ {
+ if (deployment.getURL().toString().equals(url.toString()))
+ return deployment;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Shutdown a deployment unit
+ * @param deployment The deployment unit
+ * @exception Throwable If an error occurs
+ */
+ @SuppressWarnings("unchecked")
+ void shutdownDeployment(Deployment deployment) throws Throwable
+ {
+ SecurityActions.setThreadContextClassLoader(kernelClassLoader);
+
+ try
+ {
+ Method stopMethod = deployment.getClass().getMethod("stop", (Class[])null);
+ stopMethod.invoke(deployment, (Object[])null);
+ }
+ catch (NoSuchMethodException nsme)
+ {
+ // No stop method
+ }
+ catch (InvocationTargetException ite)
+ {
+ throw ite.getCause();
+ }
+
+ try
+ {
+ Method destroyMethod = deployment.getClass().getMethod("destroy", (Class[])null);
+ destroyMethod.invoke(deployment, (Object[])null);
+ }
+ catch (NoSuchMethodException nsme)
+ {
+ // No destroy method
+ }
+ catch (InvocationTargetException ite)
+ {
+ throw ite.getCause();
+ }
+
+ deployments.remove(deployment);
+ }
+
+ /**
+ * Get the kernel class loader
+ * @return The class loader
+ */
+ public KernelClassLoader getKernelClassLoader()
+ {
+ return kernelClassLoader;
+ }
+
+ /**
+ * Get the executor service
+ * @return The executor service
+ */
+ public ExecutorService getExecutorService()
+ {
+ return threadPoolExecutor;
+ }
+
+ /**
+ * Get the bean status
+ * @param name The bean name
+ * @return The status
+ */
+ ServiceLifecycle getBeanStatus(String name)
+ {
+ return beanStatus.get(name);
+ }
+
+ /**
+ * Set the bean status
+ * @param name The bean name
+ * @param status The status
+ */
+ void setBeanStatus(String name, ServiceLifecycle status)
+ {
+ beanStatus.put(name, status);
+ }
+
+ /**
+ * Add a bean
+ * @param name The name of the bean
+ * @param bean The bean
+ */
+ void addBean(String name, Object bean)
+ {
+ beans.put(name, bean);
+ }
+
+ /**
+ * Remove a bean
+ * @param name The name of the bean
+ */
+ void removeBean(String name)
+ {
+ beans.remove(name);
+ beanStatus.remove(name);
+ }
+
+ /**
+ * Get a bean
+ * @param name The name of the bean
+ * @return The bean
+ */
+ public Object getBean(String name)
+ {
+ return beans.get(name);
+ }
+
+ /**
+ * Get the set of dependants for a bean
+ * @param name The name of the bean
+ * @return The set of dependants; <code>null</code> if there are no dependants
+ */
+ Set<String> getBeanDependants(String name)
+ {
+ return beanDependants.get(name);
+ }
+
+ /**
+ * Add a bean to the dependants map
+ * @param from The name of the from bean
+ * @param to The name of the to bean
+ */
+ void addBeanDependants(String from, String to)
+ {
+ Set<String> dependants = beanDependants.get(from);
+ if (dependants == null)
+ {
+ Set<String> newDependants = new HashSet<String>();
+ dependants = beanDependants.putIfAbsent(from, newDependants);
+ if (dependants == null)
+ {
+ dependants = newDependants;
+ }
+ }
+
+ dependants.add(to);
+ }
+
+ /**
+ * Register deployment
+ * @param deployment The deployment
+ */
+ void registerDeployment(Deployment deployment)
+ {
+ deployments.add(deployment);
+ }
+
+ /**
+ * Beans registered
+ */
+ void beansRegistered()
+ {
+ beanDeployments.decrementAndGet();
+ }
+
+ /**
+ * Is all beans registered
+ * @return True if all beans have been registered; otherwise false
+ */
+ boolean isAllBeansRegistered()
+ {
+ return beanDeployments.get() <= 0;
+ }
+
+ /**
+ * Get the main deployer
+ * @return The main deployer
+ */
+ public MainDeployer getMainDeployer()
+ {
+ try
+ {
+ return (MainDeployer)mainDeployer.clone();
+ }
+ catch (CloneNotSupportedException cnse)
+ {
+ return mainDeployer;
+ }
+ }
+
+ /**
+ * Get the URLs for the directory and all libraries located in the directory
+ * @param directrory The directory
+ * @return The URLs
+ * @exception MalformedURLException MalformedURLException
+ * @exception IOException IOException
+ */
+ private URL[] getUrls(File directory) throws MalformedURLException, IOException
+ {
+ if (directory != null && directory.exists() && directory.isDirectory())
+ {
+ List<URL> list = new LinkedList<URL>();
+
+ // Add directory
+ list.add(directory.toURI().toURL());
+
+ // Add the contents of the directory too
+ File[] jars = directory.listFiles(new JarFilter());
+
+ if (jars != null)
+ {
+ for (int j = 0; j < jars.length; j++)
+ {
+ list.add(jars[j].getCanonicalFile().toURI().toURL());
+ }
+ }
+
+ return list.toArray(new URL[list.size()]);
+ }
+
+ return new URL[0];
+ }
+
+ /**
+ * Merge URLs into a single array
+ * @param urls The URLs
+ * @return The combined list
+ */
+ private URL[] mergeUrls(URL[]... urls)
+ {
+ if (urls != null)
+ {
+ List<URL> list = new LinkedList<URL>();
+
+ for (URL[] u : urls)
+ {
+ if (u != null)
+ {
+ for (URL url : u)
+ {
+ list.add(url);
+ }
+ }
+ }
+
+ return list.toArray(new URL[list.size()]);
+ }
+
+ return new URL[0];
+ }
+
+ /**
+ * Recursive delete
+ * @param f The file handler
+ * @exception IOException Thrown if a file could not be deleted
+ */
+ private void recursiveDelete(File f) throws IOException
+ {
+ if (f != null && f.exists())
+ {
+ File[] files = f.listFiles();
+ if (files != null)
+ {
+ for (int i = 0; i < files.length; i++)
+ {
+ if (files[i].isDirectory())
+ {
+ recursiveDelete(files[i]);
+ }
+ else
+ {
+ if (!files[i].delete())
+ throw new IOException("Could not delete " + files[i]);
+ }
+ }
+ }
+ if (!f.delete())
+ throw new IOException("Could not delete " + f);
+ }
+ }
+
+ /**
+ * Init logging
+ * @param cl The classloader to load from
+ */
+ @SuppressWarnings("unchecked")
+ private void initLogging(ClassLoader cl)
+ {
+ try
+ {
+ Class clz = Class.forName("org.jboss.logmanager.log4j.BridgeRepositorySelector", true, cl);
+ Method mStart = clz.getMethod("start", (Class[])null);
+
+ Object brs = clz.newInstance();
+
+ logging = mStart.invoke(brs, (Object[])null);
+ }
+ catch (Throwable t)
+ {
+ // Nothing we can do
+ }
+
+
+ try
+ {
+ Class clz = Class.forName("org.jboss.logging.Logger", true, cl);
+
+ Method mGetLogger = clz.getMethod("getLogger", String.class);
+
+ logging = mGetLogger.invoke((Object)null, new Object[] {"org.jboss.jca.fungal.impl.KernelImpl"});
+ }
+ catch (Throwable t)
+ {
+ // Nothing we can do
+ }
+ }
+
+ /**
+ * Logging: ERROR
+ * @param s The string
+ * @param t The throwable
+ */
+ @SuppressWarnings("unchecked")
+ private void error(String s, Throwable t)
+ {
+ if (logging != null)
+ {
+ try
+ {
+ Class clz = logging.getClass();
+ Method mError = clz.getMethod("error", Object.class, Throwable.class);
+ mError.invoke(logging, new Object[] {s, t});
+ }
+ catch (Throwable th)
+ {
+ // Nothing we can do
+ }
+ }
+ else
+ {
+ System.out.println(s);
+ t.printStackTrace(System.out);
+ }
+ }
+
+ /**
+ * Logging: WARN
+ * @param s The string
+ */
+ @SuppressWarnings("unchecked")
+ private void warn(String s)
+ {
+ if (logging != null)
+ {
+ try
+ {
+ Class clz = logging.getClass();
+ Method mWarn = clz.getMethod("warn", Object.class);
+ mWarn.invoke(logging, new Object[] {s});
+ }
+ catch (Throwable t)
+ {
+ // Nothing we can do
+ }
+ }
+ else
+ {
+ System.out.println(s);
+ }
+ }
+
+ /**
+ * Logging: INFO
+ * @param s The string
+ */
+ @SuppressWarnings("unchecked")
+ private void info(String s)
+ {
+ if (logging != null)
+ {
+ try
+ {
+ Class clz = logging.getClass();
+ Method mInfo = clz.getMethod("info", Object.class);
+ mInfo.invoke(logging, new Object[] {s});
+ }
+ catch (Throwable t)
+ {
+ // Nothing we can do
+ }
+ }
+ else
+ {
+ System.out.println(s);
+ }
+ }
+
+ /**
+ * Logging: Is DEBUG enabled
+ * @return True if debug is enabled; otherwise false
+ */
+ @SuppressWarnings("unchecked")
+ private boolean isDebugEnabled()
+ {
+ if (logging != null)
+ {
+ try
+ {
+ Class clz = logging.getClass();
+ Method mIsDebugEnabled = clz.getMethod("isDebugEnabled", (Class[])null);
+ return ((Boolean)mIsDebugEnabled.invoke(logging, (Object[])null)).booleanValue();
+ }
+ catch (Throwable t)
+ {
+ // Nothing we can do
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Logging: DEBUG
+ * @param s The string
+ */
+ @SuppressWarnings("unchecked")
+ private void debug(String s)
+ {
+ if (logging != null)
+ {
+ try
+ {
+ Class clz = logging.getClass();
+ Method mDebug = clz.getMethod("debug", Object.class);
+ mDebug.invoke(logging, new Object[] {s});
+ }
+ catch (Throwable t)
+ {
+ // Nothing we can do
+ }
+ }
+ else
+ {
+ System.out.println(s);
+ }
+ }
+
+ /**
+ * Unit deployer
+ */
+ static class UnitDeployer implements Runnable
+ {
+ /** Unit URL */
+ private URL url;
+
+ /** Main deployer */
+ private MainDeployerImpl deployer;
+
+ /** Class loader */
+ private ClassLoader classLoader;
+
+ /** Unit latch */
+ private CountDownLatch unitLatch;
+
+ /** Throwable */
+ private Throwable throwable;
+
+ /**
+ * Constructor
+ * @param url The deployment url
+ * @param deployer The main deployer
+ * @param classLoader The class loader
+ * @param unitLatch The unit latch
+ */
+ public UnitDeployer(final URL url,
+ final MainDeployerImpl deployer,
+ final ClassLoader classLoader,
+ final CountDownLatch unitLatch)
+ {
+ this.url = url;
+ this.deployer = deployer;
+ this.classLoader = classLoader;
+ this.unitLatch = unitLatch;
+ this.throwable = null;
+ }
+
+ /**
+ * Run
+ */
+ public void run()
+ {
+ SecurityActions.setThreadContextClassLoader(classLoader);
+
+ try
+ {
+ deployer.deploy(url, classLoader);
+ }
+ catch (Throwable t)
+ {
+ throwable = t;
+ }
+
+ unitLatch.countDown();
+ }
+
+ /**
+ * Get deploy exception
+ * @return null if no error; otherwise the exception
+ */
+ public Throwable getThrowable()
+ {
+ return throwable;
+ }
+ }
+}
Deleted: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/MainDeployerImpl.java
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/MainDeployerImpl.java 2009-11-30 11:05:54 UTC (rev 97161)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/MainDeployerImpl.java 2009-11-30 14:38:21 UTC (rev 97166)
@@ -1,158 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This 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.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.jca.fungal.impl;
-
-import org.jboss.jca.fungal.deployers.CloneableDeployer;
-import org.jboss.jca.fungal.deployers.Deployer;
-import org.jboss.jca.fungal.deployers.Deployment;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-/**
- * The main deployer for JBoss JCA/Fungal
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- */
-public class MainDeployerImpl implements Cloneable, MainDeployerImplMBean
-{
- private static List<Deployer> deployers = new CopyOnWriteArrayList<Deployer>();
-
- private KernelImpl kernel;
- private List<Deployer> copy;
-
- /**
- * Constructor
- * @param kernel The kernel
- */
- public MainDeployerImpl(KernelImpl kernel)
- {
- if (kernel == null)
- throw new IllegalArgumentException("Kernel is null");
-
- this.kernel = kernel;
- this.copy = null;
- }
-
- /**
- * Add deployer
- * @param deployer The deployer
- */
- public void addDeployer(Deployer deployer)
- {
- if (deployer == null)
- throw new IllegalArgumentException("Deployer is null");
-
- deployers.add(deployer);
- }
-
- /**
- * Deploy uses the kernel class loader as the parent class loader
- * @param url The URL for the deployment
- * @exception Throwable If an error occurs
- */
- public synchronized void deploy(URL url) throws Throwable
- {
- deploy(url, kernel.getKernelClassLoader());
- }
-
- /**
- * Deploy
- * @param url The URL for the deployment
- * @param classLoader The parent class loader for the deployment
- * @exception Throwable If an error occurs
- */
- public synchronized void deploy(URL url, ClassLoader classLoader) throws Throwable
- {
- if (url == null)
- throw new IllegalArgumentException("URL is null");
-
- if (classLoader == null)
- throw new IllegalArgumentException("ClassLoader is null");
-
- if (copy == null || copy.size() != deployers.size())
- {
- copy = new ArrayList<Deployer>(deployers.size());
- for (Deployer deployer : deployers)
- {
- if (deployer instanceof CloneableDeployer)
- {
- try
- {
- copy.add(((CloneableDeployer)deployer).clone());
- }
- catch (CloneNotSupportedException cnse)
- {
- // Add the deployer and assume synchronized access
- copy.add(deployer);
- }
- }
- else
- {
- // Assume synchronized access to deploy()
- copy.add(deployer);
- }
- }
- }
-
- boolean done = false;
-
- for (int i = 0; !done && i < copy.size(); i++)
- {
- Deployer deployer = copy.get(i);
-
- Deployment deployment = deployer.deploy(url, classLoader);
- if (deployment != null)
- {
- kernel.registerDeployment(deployment);
- done = true;
- }
- }
- }
-
- /**
- * Undeploy
- * @param url The URL for the deployment
- * @exception Throwable If an error occurs
- */
- public synchronized void undeploy(URL url) throws Throwable
- {
- if (url == null)
- throw new IllegalArgumentException("URL is null");
-
- Deployment deployment = kernel.findDeployment(url);
- if (deployment != null)
- kernel.shutdownDeployment(deployment);
- }
-
- /**
- * Clone
- * @return The copy of the object
- * @exception CloneNotSupportedException Thrown if a copy can't be created
- */
- public Object clone() throws CloneNotSupportedException
- {
- return new MainDeployerImpl(kernel);
- }
-}
Copied: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/MainDeployerImpl.java (from rev 97165, projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/MainDeployerImpl.java)
===================================================================
--- projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/MainDeployerImpl.java (rev 0)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/fungal/src/main/java/org/jboss/jca/fungal/impl/MainDeployerImpl.java 2009-11-30 14:38:21 UTC (rev 97166)
@@ -0,0 +1,158 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This 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.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.fungal.impl;
+
+import org.jboss.jca.fungal.deployers.CloneableDeployer;
+import org.jboss.jca.fungal.deployers.Deployer;
+import org.jboss.jca.fungal.deployers.Deployment;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+/**
+ * The main deployer for JBoss JCA/Fungal
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public final class MainDeployerImpl implements Cloneable, MainDeployerImplMBean
+{
+ private static List<Deployer> deployers = new CopyOnWriteArrayList<Deployer>();
+
+ private KernelImpl kernel;
+ private List<Deployer> copy;
+
+ /**
+ * Constructor
+ * @param kernel The kernel
+ */
+ public MainDeployerImpl(KernelImpl kernel)
+ {
+ if (kernel == null)
+ throw new IllegalArgumentException("Kernel is null");
+
+ this.kernel = kernel;
+ this.copy = null;
+ }
+
+ /**
+ * Add deployer
+ * @param deployer The deployer
+ */
+ public void addDeployer(Deployer deployer)
+ {
+ if (deployer == null)
+ throw new IllegalArgumentException("Deployer is null");
+
+ deployers.add(deployer);
+ }
+
+ /**
+ * Deploy uses the kernel class loader as the parent class loader
+ * @param url The URL for the deployment
+ * @exception Throwable If an error occurs
+ */
+ public synchronized void deploy(URL url) throws Throwable
+ {
+ deploy(url, kernel.getKernelClassLoader());
+ }
+
+ /**
+ * Deploy
+ * @param url The URL for the deployment
+ * @param classLoader The parent class loader for the deployment
+ * @exception Throwable If an error occurs
+ */
+ public synchronized void deploy(URL url, ClassLoader classLoader) throws Throwable
+ {
+ if (url == null)
+ throw new IllegalArgumentException("URL is null");
+
+ if (classLoader == null)
+ throw new IllegalArgumentException("ClassLoader is null");
+
+ if (copy == null || copy.size() != deployers.size())
+ {
+ copy = new ArrayList<Deployer>(deployers.size());
+ for (Deployer deployer : deployers)
+ {
+ if (deployer instanceof CloneableDeployer)
+ {
+ try
+ {
+ copy.add(((CloneableDeployer)deployer).clone());
+ }
+ catch (CloneNotSupportedException cnse)
+ {
+ // Add the deployer and assume synchronized access
+ copy.add(deployer);
+ }
+ }
+ else
+ {
+ // Assume synchronized access to deploy()
+ copy.add(deployer);
+ }
+ }
+ }
+
+ boolean done = false;
+
+ for (int i = 0; !done && i < copy.size(); i++)
+ {
+ Deployer deployer = copy.get(i);
+
+ Deployment deployment = deployer.deploy(url, classLoader);
+ if (deployment != null)
+ {
+ kernel.registerDeployment(deployment);
+ done = true;
+ }
+ }
+ }
+
+ /**
+ * Undeploy
+ * @param url The URL for the deployment
+ * @exception Throwable If an error occurs
+ */
+ public synchronized void undeploy(URL url) throws Throwable
+ {
+ if (url == null)
+ throw new IllegalArgumentException("URL is null");
+
+ Deployment deployment = kernel.findDeployment(url);
+ if (deployment != null)
+ kernel.shutdownDeployment(deployment);
+ }
+
+ /**
+ * Clone
+ * @return The copy of the object
+ * @exception CloneNotSupportedException Thrown if a copy can't be created
+ */
+ public Object clone() throws CloneNotSupportedException
+ {
+ return new MainDeployerImpl(kernel);
+ }
+}
Deleted: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/tools/findbugs/filter.xml
===================================================================
--- projects/jboss-jca/trunk/tools/findbugs/filter.xml 2009-11-30 11:05:54 UTC (rev 97161)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/tools/findbugs/filter.xml 2009-11-30 14:38:21 UTC (rev 97166)
@@ -1,119 +0,0 @@
-<FindBugsFilter>
-
- <!-- javax.resource filter -->
- <Match>
- <Class name="javax.resource.Referenceable"/>
- <Bug code="Nm"/>
- </Match>
- <Match>
- <Class name="javax.resource.cci.ResultSet"/>
- <Bug code="Nm"/>
- </Match>
- <Match>
- <Class name="javax.resource.spi.InvalidPropertyException"/>
- <Bug code="EI,EI2,Se"/>
- </Match>
- <Match>
- <Class name="javax.resource.spi.security.PasswordCredential"/>
- <Bug code="EI"/>
- </Match>
- <Match>
- <Class name="javax.resource.spi.work.HintsContext"/>
- <Bug code="Se"/>
- </Match>
-
- <!-- org.jboss.jca.common filter -->
- <Match>
- <Class name="org.jboss.jca.common.api.ThreadPool"/>
- <Bug code="Nm"/>
- </Match>
-
- <!-- org.jboss.jca.core filter -->
- <Match>
- <Class name="org.jboss.jca.core.api.ConnectionManager"/>
- <Bug code="Nm"/>
- </Match>
- <Match>
- <Class name="org.jboss.jca.core.api.WorkManager"/>
- <Bug code="Nm"/>
- </Match>
-
- <!-- org.jboss.jca.deployers filter -->
- <Match>
- <Class name="org.jboss.jca.deployers.fungal.RADeployer"/>
- <Bug code="DLS"/>
- </Match>
-
- <!-- org.jboss.jca.fungal filter -->
- <Match>
- <Class name="org.jboss.jca.fungal.impl.DeploymentDeployer"/>
- <Bug code="DLS,UPM"/>
- </Match>
- <Match>
- <Class name="org.jboss.jca.fungal.impl.KernelImpl"/>
- <Bug code="DLS,UPM"/>
- </Match>
- <Match>
- <Class name="org.jboss.jca.fungal.impl.remote.Communication"/>
- <Bug code="UPM"/>
- </Match>
- <Match>
- <Class name="org.jboss.jca.fungal.impl.remote.CommunicationServer"/>
- <Bug code="DLS,UPM"/>
- </Match>
-
- <!-- org.jboss.jca.sjc filter -->
- <Match>
- <Class name="org.jboss.jca.sjc.Main"/>
- <Bug code="UPM"/>
- </Match>
- <Match>
- <Class name="org.jboss.jca.sjc.Main$LifeThread"/>
- <Bug code="UW,Wa"/>
- </Match>
-
- <!-- org.jboss.jca.standalone filter -->
- <Match>
- <Class name="org.jboss.jca.standalone.Main"/>
- <Bug code="UPM"/>
- </Match>
-
- <!-- org.jboss.jca.web filter -->
- <Match>
- <Class name="org.jboss.jca.web.WARDeployment"/>
- <Bug code="UrF"/>
- </Match>
- <Match>
- <Class name="org.jboss.jca.web.console.HtmlAdaptorServlet"/>
- <Bug code="DLS"/>
- </Match>
- <Match>
- <Class name="org.jboss.jca.web.console.HtmlAdaptorServlet$1"/>
- <Bug code="SIC"/>
- </Match>
- <Match>
- <Class name="org.jboss.jca.web.console.HtmlAdaptorServlet$2"/>
- <Bug code="SIC"/>
- </Match>
- <Match>
- <Class name="org.jboss.jca.web.console.HtmlAdaptorServlet$3"/>
- <Bug code="SIC"/>
- </Match>
- <Match>
- <Class name="org.jboss.jca.web.console.HtmlAdaptorServlet$4"/>
- <Bug code="SIC"/>
- </Match>
- <Match>
- <Class name="org.jboss.jca.web.console.HtmlAdaptorServlet$5"/>
- <Bug code="SIC"/>
- </Match>
- <Match>
- <Class name="org.jboss.jca.web.console.OpResultInfo"/>
- <Bug code="EI,EI2"/>
- </Match>
- <Match>
- <Class name="org.jboss.jca.web.console.Server"/>
- <Bug code="RCN"/>
- </Match>
-
-</FindBugsFilter>
Copied: projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/tools/findbugs/filter.xml (from rev 97165, projects/jboss-jca/trunk/tools/findbugs/filter.xml)
===================================================================
--- projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/tools/findbugs/filter.xml (rev 0)
+++ projects/jboss-jca/tags/JBOSS_JCA_1_0_0_ALPHA6/tools/findbugs/filter.xml 2009-11-30 14:38:21 UTC (rev 97166)
@@ -0,0 +1,123 @@
+<FindBugsFilter>
+
+ <!-- javax.resource filter -->
+ <Match>
+ <Class name="javax.resource.Referenceable"/>
+ <Bug code="Nm"/>
+ </Match>
+ <Match>
+ <Class name="javax.resource.cci.ResultSet"/>
+ <Bug code="Nm"/>
+ </Match>
+ <Match>
+ <Class name="javax.resource.spi.InvalidPropertyException"/>
+ <Bug code="EI,EI2,Se"/>
+ </Match>
+ <Match>
+ <Class name="javax.resource.spi.security.PasswordCredential"/>
+ <Bug code="EI"/>
+ </Match>
+ <Match>
+ <Class name="javax.resource.spi.work.HintsContext"/>
+ <Bug code="Se"/>
+ </Match>
+
+ <!-- org.jboss.jca.common filter -->
+ <Match>
+ <Class name="org.jboss.jca.common.api.ThreadPool"/>
+ <Bug code="Nm"/>
+ </Match>
+
+ <!-- org.jboss.jca.core filter -->
+ <Match>
+ <Class name="org.jboss.jca.core.api.ConnectionManager"/>
+ <Bug code="Nm"/>
+ </Match>
+ <Match>
+ <Class name="org.jboss.jca.core.api.WorkManager"/>
+ <Bug code="Nm"/>
+ </Match>
+
+ <!-- org.jboss.jca.deployers filter -->
+ <Match>
+ <Class name="org.jboss.jca.deployers.fungal.RADeployer"/>
+ <Bug code="DLS"/>
+ </Match>
+
+ <!-- org.jboss.jca.fungal filter -->
+ <Match>
+ <Class name="org.jboss.jca.fungal.impl.DeploymentDeployer"/>
+ <Bug code="DLS,UPM"/>
+ </Match>
+ <Match>
+ <Class name="org.jboss.jca.fungal.impl.KernelImpl"/>
+ <Bug code="DLS,UPM"/>
+ </Match>
+ <Match>
+ <Class name="org.jboss.jca.fungal.impl.remote.Communication"/>
+ <Bug code="UPM"/>
+ </Match>
+ <Match>
+ <Class name="org.jboss.jca.fungal.impl.remote.CommunicationServer"/>
+ <Bug code="DLS,UPM"/>
+ </Match>
+
+ <!-- org.jboss.jca.sjc filter -->
+ <Match>
+ <Class name="org.jboss.jca.sjc.Main"/>
+ <Bug code="UPM"/>
+ </Match>
+ <Match>
+ <Class name="org.jboss.jca.sjc.Main$LifeThread"/>
+ <Bug code="UW,Wa"/>
+ </Match>
+
+ <!-- org.jboss.jca.standalone filter -->
+ <Match>
+ <Class name="org.jboss.jca.standalone.Main"/>
+ <Bug code="UPM"/>
+ </Match>
+
+ <!-- org.jboss.jca.web filter -->
+ <Match>
+ <Class name="org.jboss.jca.web.WARDeployer"/>
+ <Bug code="IS"/>
+ </Match>
+ <Match>
+ <Class name="org.jboss.jca.web.WARDeployment"/>
+ <Bug code="UrF"/>
+ </Match>
+ <Match>
+ <Class name="org.jboss.jca.web.console.HtmlAdaptorServlet"/>
+ <Bug code="DLS"/>
+ </Match>
+ <Match>
+ <Class name="org.jboss.jca.web.console.HtmlAdaptorServlet$1"/>
+ <Bug code="SIC"/>
+ </Match>
+ <Match>
+ <Class name="org.jboss.jca.web.console.HtmlAdaptorServlet$2"/>
+ <Bug code="SIC"/>
+ </Match>
+ <Match>
+ <Class name="org.jboss.jca.web.console.HtmlAdaptorServlet$3"/>
+ <Bug code="SIC"/>
+ </Match>
+ <Match>
+ <Class name="org.jboss.jca.web.console.HtmlAdaptorServlet$4"/>
+ <Bug code="SIC"/>
+ </Match>
+ <Match>
+ <Class name="org.jboss.jca.web.console.HtmlAdaptorServlet$5"/>
+ <Bug code="SIC"/>
+ </Match>
+ <Match>
+ <Class name="org.jboss.jca.web.console.OpResultInfo"/>
+ <Bug code="EI,EI2"/>
+ </Match>
+ <Match>
+ <Class name="org.jboss.jca.web.console.Server"/>
+ <Bug code="RCN"/>
+ </Match>
+
+</FindBugsFilter>
More information about the jboss-cvs-commits
mailing list