From 64ca1c8f3a8ac96dfe14c1b217e0b369524eda9a Mon Sep 17 00:00:00 2001 From: willemc Date: Sat, 26 Apr 2008 02:30:39 +0200 Subject: [PATCH] [svn r331] made the SPI interface also work. --- meta/jboss/ra.xml | 4 +- .../foei/core/FoeiProcessListener.java | 42 +++++++++ .../idcanet/foei/core/FoeiProcessManager.java | 4 + .../core/impl/FoeiProcessManagerImpl.java | 27 ++++++ .../ee/jca/cci/EJBFoeiProcessListener.java | 85 +++++++++++++++++++ .../jca/cci/FoeiManagedConnectionFactory.java | 7 +- .../idcanet/foei/ee/jca/spi/EJBFoeiBean.java | 45 ++++++++++ .../foei/ee/jca/spi/FoeiActivationSpec.java | 74 +++++++++++++--- .../foei/ee/jca/spi/FoeiEventWrapper.java | 72 +++++++++++++--- .../foei/ee/jca/spi/FoeiResourceAdapter.java | 60 +++++++------ 10 files changed, 371 insertions(+), 49 deletions(-) create mode 100644 src/com/idcanet/foei/core/FoeiProcessListener.java create mode 100644 src/com/idcanet/foei/ee/jca/cci/EJBFoeiProcessListener.java create mode 100644 src/com/idcanet/foei/ee/jca/spi/EJBFoeiBean.java diff --git a/meta/jboss/ra.xml b/meta/jboss/ra.xml index 5b36428..d3e58e7 100644 --- a/meta/jboss/ra.xml +++ b/meta/jboss/ra.xml @@ -62,11 +62,11 @@ should not be interpreted as representing official policies, either expressed or - com.idcanet.foei.event.EventInput + com.idcanet.foei.ee.jca.spi.EJBFoeiBean com.idcanet.foei.ee.jca.spi.FoeiActivationSpec - beanName + foeiBeanName diff --git a/src/com/idcanet/foei/core/FoeiProcessListener.java b/src/com/idcanet/foei/core/FoeiProcessListener.java new file mode 100644 index 0000000..3f989c7 --- /dev/null +++ b/src/com/idcanet/foei/core/FoeiProcessListener.java @@ -0,0 +1,42 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core; + +/** + * Gets called when process is created or destroyed.
+ * + * + * @author Willem Cazander + * @version 1.0 Apr 26, 2008 + */ +public interface FoeiProcessListener { + + public void foeiProcessCreated(FoeiProcess process); + + public void foeiProcessDestroyed(FoeiProcess process); + +} \ No newline at end of file diff --git a/src/com/idcanet/foei/core/FoeiProcessManager.java b/src/com/idcanet/foei/core/FoeiProcessManager.java index 6501a7c..b5b7eb0 100644 --- a/src/com/idcanet/foei/core/FoeiProcessManager.java +++ b/src/com/idcanet/foei/core/FoeiProcessManager.java @@ -63,4 +63,8 @@ public interface FoeiProcessManager { * @return */ public Collection getFoeiProcesses(); + + public void addFoeiProcessListener(FoeiProcessListener foeiProcessListener); + + public void removeFoeiProcessListener(FoeiProcessListener foeiProcessListener); } \ No newline at end of file diff --git a/src/com/idcanet/foei/core/impl/FoeiProcessManagerImpl.java b/src/com/idcanet/foei/core/impl/FoeiProcessManagerImpl.java index 1c5bc89..7034497 100644 --- a/src/com/idcanet/foei/core/impl/FoeiProcessManagerImpl.java +++ b/src/com/idcanet/foei/core/impl/FoeiProcessManagerImpl.java @@ -28,11 +28,14 @@ package com.idcanet.foei.core.impl; import com.idcanet.foei.core.FoeiContext; import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.core.FoeiProcessListener; import com.idcanet.foei.core.FoeiProcessManager; import com.idcanet.foei.core.ObjectBindingsManager; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.logging.Level; @@ -53,12 +56,15 @@ public class FoeiProcessManagerImpl implements FoeiProcessManager { /** The logger to log to. */ private Logger logger = null; + private List foeiProcessListeners = null; + /** * Creates an FoeiProcessManagerImpl */ public FoeiProcessManagerImpl() { logger = Logger.getLogger(FoeiProcessManagerImpl.class.getName()); foeiProcesses = new HashMap(5); + foeiProcessListeners = new ArrayList(5); } /** @@ -78,6 +84,10 @@ public class FoeiProcessManagerImpl implements FoeiProcessManager { synchronized (foeiProcesses) { foeiProcesses.put(fp.getName(),fp); } + for (FoeiProcessListener l:foeiProcessListeners) { + l.foeiProcessCreated(fp); + } + logger.finer("FoeiProcess created and added total processes: "+foeiProcesses.size()); return fp; } catch (Exception e) { @@ -98,6 +108,9 @@ public class FoeiProcessManagerImpl implements FoeiProcessManager { synchronized (foeiProcesses) { foeiProcesses.remove(p.getName()); } + for (FoeiProcessListener l:foeiProcessListeners) { + l.foeiProcessDestroyed(p); + } logger.finer("FoeiProcess destroyed total processes: "+foeiProcesses.size()); try { p.getFoeiContext().getEventObjectContext().destroySubcontext(p.getName()); @@ -122,4 +135,18 @@ public class FoeiProcessManagerImpl implements FoeiProcessManager { public Collection getFoeiProcesses() { return foeiProcesses.values(); } + + /** + * @see com.idcanet.foei.core.FoeiProcessManager#addFoeiProcessListener(com.idcanet.foei.core.FoeiProcessListener) + */ + public void addFoeiProcessListener(FoeiProcessListener foeiProcessListener) { + foeiProcessListeners.add(foeiProcessListener); + } + + /** + * @see com.idcanet.foei.core.FoeiProcessManager#removeFoeiProcessListener(com.idcanet.foei.core.FoeiProcessListener) + */ + public void removeFoeiProcessListener(FoeiProcessListener foeiProcessListener) { + foeiProcessListeners.remove(foeiProcessListener); + } } \ No newline at end of file diff --git a/src/com/idcanet/foei/ee/jca/cci/EJBFoeiProcessListener.java b/src/com/idcanet/foei/ee/jca/cci/EJBFoeiProcessListener.java new file mode 100644 index 0000000..1b48918 --- /dev/null +++ b/src/com/idcanet/foei/ee/jca/cci/EJBFoeiProcessListener.java @@ -0,0 +1,85 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.ee.jca.cci; + +import javax.resource.spi.endpoint.MessageEndpointFactory; + +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.core.FoeiProcessListener; +import com.idcanet.foei.ee.jca.spi.FoeiActivationSpec; +import com.idcanet.foei.ee.jca.spi.FoeiEventWrapper; +import com.idcanet.foei.ee.jca.spi.FoeiResourceAdapter; + +/** + * Injects the ejb3 beans in the process.
+ * + * + * @author Willem Cazander + * @version 1.0 Apr 26, 2008 + */ +public class EJBFoeiProcessListener implements FoeiProcessListener { + + private FoeiResourceAdapter foeiResourceAdapter = null; + + + public EJBFoeiProcessListener(FoeiResourceAdapter foeiResourceAdapter) { + this.foeiResourceAdapter=foeiResourceAdapter; + } + + /** + * @see com.idcanet.foei.core.FoeiProcessListener#foeiProcessCreated(com.idcanet.foei.core.FoeiProcess) + */ + public void foeiProcessCreated(FoeiProcess process) { + + // list all beans. + for (String name:foeiResourceAdapter.getEJBFoeiBeanNames()) { + + FoeiActivationSpec foeiActivationSpec = foeiResourceAdapter.getFoeiActivationSpec(name); + MessageEndpointFactory endpointFactory = foeiResourceAdapter.getMessageEndpointFactory(name); + + // check context name + if (process.getFoeiContext().getName().matches(foeiActivationSpec.getFoeiContextName())) { + + // check process name + if (process.getName().matches(foeiActivationSpec.getFoeiProcessName())) { + + // create wrapper for in foei, which can get an instance of the EJB bean. + FoeiEventWrapper wrapper = new FoeiEventWrapper(endpointFactory,process); + + // inject bean + process.addEventObject(wrapper, foeiActivationSpec.getFoeiBeanName()); + } + } + } + } + + /** + * @see com.idcanet.foei.core.FoeiProcessListener#foeiProcessDestroyed(com.idcanet.foei.core.FoeiProcess) + */ + public void foeiProcessDestroyed(FoeiProcess process) { + } +} \ No newline at end of file diff --git a/src/com/idcanet/foei/ee/jca/cci/FoeiManagedConnectionFactory.java b/src/com/idcanet/foei/ee/jca/cci/FoeiManagedConnectionFactory.java index b8b9caa..da206dc 100644 --- a/src/com/idcanet/foei/ee/jca/cci/FoeiManagedConnectionFactory.java +++ b/src/com/idcanet/foei/ee/jca/cci/FoeiManagedConnectionFactory.java @@ -86,8 +86,13 @@ public class FoeiManagedConnectionFactory implements ManagedConnectionFactory,Re Map properties = new HashMap(0); try { objectContext = FoeiConfiguratorImpl.newContext(properties); - eventExecutorManager = new JCAEventExecutorManager((FoeiResourceAdapter)getResourceAdapter()); + //eventExecutorManager = new JCAEventExecutorManager((FoeiResourceAdapter)getResourceAdapter()); + eventExecutorManager = FoeiConfiguratorImpl.newEventExecutorManager(properties); foeiProcessManager = FoeiConfiguratorImpl.newFoeiProcessManager(properties); + + // inject ejb beans per process + foeiProcessManager.addFoeiProcessListener(new EJBFoeiProcessListener((FoeiResourceAdapter)getResourceAdapter())); + FoeiConfiguratorImpl.loadEventThreadListeners(properties,eventExecutorManager); } catch (Exception e) { throw new ResourceException("Error while building childs objects:",e); diff --git a/src/com/idcanet/foei/ee/jca/spi/EJBFoeiBean.java b/src/com/idcanet/foei/ee/jca/spi/EJBFoeiBean.java new file mode 100644 index 0000000..57cdd60 --- /dev/null +++ b/src/com/idcanet/foei/ee/jca/spi/EJBFoeiBean.java @@ -0,0 +1,45 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.ee.jca.spi; + +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.event.EventInput; +import com.idcanet.foei.event.EventOutput; +import com.idcanet.foei.event.EventPort; +import com.idcanet.foei.event.IllegalEventPortNameException; + +/** + * Gets called when process is created or destroyed.
+ * + * + * @author Willem Cazander + * @version 1.0 Apr 26, 2008 + */ +public interface EJBFoeiBean extends EventInput,EventOutput { + + public void doEvent(FoeiProcess process,EventPort eventPort,Object object) throws IllegalEventPortNameException; +} \ No newline at end of file diff --git a/src/com/idcanet/foei/ee/jca/spi/FoeiActivationSpec.java b/src/com/idcanet/foei/ee/jca/spi/FoeiActivationSpec.java index e80ddc3..72ea2a9 100644 --- a/src/com/idcanet/foei/ee/jca/spi/FoeiActivationSpec.java +++ b/src/com/idcanet/foei/ee/jca/spi/FoeiActivationSpec.java @@ -45,18 +45,42 @@ public class FoeiActivationSpec implements ActivationSpec, Serializable { /** The resource adapter */ private transient ResourceAdapter resourceAdapter = null; - private String beanName = null; + private String foeiBeanName = null; + + private String foeiProcessName = null; + + private String foeiContextName = null; /** * @see javax.resource.spi.ActivationSpec#validate() */ public void validate() throws InvalidPropertyException { - if (beanName==null) { - throw new InvalidPropertyException("beanName is null,please set beanName property."); + if (foeiBeanName==null) { + throw new InvalidPropertyException("foeiBeanName is null,please set foeiBeanName property."); } - if (beanName.isEmpty()) { - throw new InvalidPropertyException("beanName is empty,please set beanName property."); + if (foeiBeanName.isEmpty()) { + throw new InvalidPropertyException("foeiBeanName is empty,please set foeiBeanName property."); } + if (foeiProcessName==null) { + foeiProcessName=".*"; + } + if (foeiProcessName.isEmpty()) { + foeiProcessName=".*"; + } + if ("*".equals(foeiProcessName)) { + foeiProcessName=".*"; + } + if (foeiContextName==null) { + foeiContextName=".*"; + } + if (foeiContextName.isEmpty()) { + foeiContextName=".*"; + } + if ("*".equals(foeiContextName)) { + foeiContextName=".*"; + } + + // TODO: check if is regex } /** @@ -77,16 +101,44 @@ public class FoeiActivationSpec implements ActivationSpec, Serializable { } /** - * @return the beanName + * @return the foeiBeanName */ - public String getBeanName() { - return beanName; + public String getFoeiBeanName() { + return foeiBeanName; } /** - * @param beanName the beanName to set + * @param foeiBeanName the foeiBeanName to set */ - public void setBeanName(String beanName) { - this.beanName = beanName; + public void setFoeiBeanName(String foeiBeanName) { + this.foeiBeanName = foeiBeanName; + } + + /** + * @return the foeiProcessName + */ + public String getFoeiProcessName() { + return foeiProcessName; + } + + /** + * @param foeiProcessName the foeiProcessName to set + */ + public void setFoeiProcessName(String foeiProcessName) { + this.foeiProcessName = foeiProcessName; + } + + /** + * @return the foeiContextName + */ + public String getFoeiContextName() { + return foeiContextName; + } + + /** + * @param foeiContextName the foeiContextName to set + */ + public void setFoeiContextName(String foeiContextName) { + this.foeiContextName = foeiContextName; } } \ No newline at end of file diff --git a/src/com/idcanet/foei/ee/jca/spi/FoeiEventWrapper.java b/src/com/idcanet/foei/ee/jca/spi/FoeiEventWrapper.java index cc82780..451f97b 100644 --- a/src/com/idcanet/foei/ee/jca/spi/FoeiEventWrapper.java +++ b/src/com/idcanet/foei/ee/jca/spi/FoeiEventWrapper.java @@ -29,35 +29,85 @@ package com.idcanet.foei.ee.jca.spi; import java.util.logging.Logger; import javax.resource.spi.endpoint.MessageEndpoint; +import javax.resource.spi.endpoint.MessageEndpointFactory; -import com.idcanet.foei.event.AbstractEventInput; +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.event.AbstractEventObject; import com.idcanet.foei.event.EventPort; import com.idcanet.foei.event.IllegalEventPortNameException; /** - * + * Wrappers the ejb bean into the foei executing context. * * @author Willem Cazander * @version 1.0 Apr 19, 2008 */ @SuppressWarnings("serial") -public class FoeiEventWrapper extends AbstractEventInput { +public class FoeiEventWrapper extends AbstractEventObject { private Logger logger = Logger.getLogger(FoeiEventWrapper.class.getName()); + private MessageEndpointFactory endpointFactory = null; + + private FoeiProcess foeiProcess = null; + + public FoeiEventWrapper(MessageEndpointFactory endpointFactory,FoeiProcess foeiProcess) { + this.endpointFactory=endpointFactory; + this.foeiProcess=foeiProcess; + + MessageEndpoint endpoint = null; + try { + endpoint = endpointFactory.createEndpoint(null); // creates new EJB3 bean instance !! + if (endpoint != null) { + EJBFoeiBean bean = (EJBFoeiBean) endpoint; + + // copy ports, todo: go to annotations + + // TODO: check if has input port at all... + for (EventPort p:bean.getInputPorts()) { + this.addInputPort(p.getName(), p.getObjectClass()); + } + for (EventPort p:bean.getOutputPorts()) { + this.addOutputPort(p.getName(), p.getObjectClass()); + } + + } else { + logger.warning("MessageEndPoint is null."); + } + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + if (endpoint != null) { + endpoint.release(); + } + } + + } + /** * @see com.idcanet.foei.event.AbstractEventInput#doEvent(com.idcanet.foei.event.EventPort, java.lang.Object) */ @Override public void doEvent(EventPort eventPort, Object object) throws IllegalEventPortNameException { MessageEndpoint endpoint = null; - //MessageEndpointFactory endpointFactory = null; //(MessageEndpointFactory)"endpointFactory"; - //endpoint = endpointFactory.createEndpoint(null); - if (endpoint != null) { - AbstractEventInput input = (AbstractEventInput) endpoint; - input.doEvent(eventPort, object); - } else { - logger.warning("MessageEndPoint is null."); - } + try { + endpoint = endpointFactory.createEndpoint(null); // creates new EJB3 bean instance !! + if (endpoint != null) { + EJBFoeiBean input = (EJBFoeiBean) endpoint; + + // mmm needed ? + // yes for normaly equals .. + EventPort port = input.getInputPort(eventPort.getName()); + input.doEvent(foeiProcess,port, object); + } else { + logger.warning("MessageEndPoint is null."); + } + } catch (Exception e) { + throw new IllegalEventPortNameException(e); + } finally { + if (endpoint != null) { + endpoint.release(); // release ejb bean + } + } } } \ No newline at end of file diff --git a/src/com/idcanet/foei/ee/jca/spi/FoeiResourceAdapter.java b/src/com/idcanet/foei/ee/jca/spi/FoeiResourceAdapter.java index 06318d1..510a6b9 100644 --- a/src/com/idcanet/foei/ee/jca/spi/FoeiResourceAdapter.java +++ b/src/com/idcanet/foei/ee/jca/spi/FoeiResourceAdapter.java @@ -26,7 +26,10 @@ package com.idcanet.foei.ee.jca.spi; -import java.util.logging.Level; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.logging.Logger; import javax.resource.ResourceException; @@ -34,12 +37,9 @@ import javax.resource.spi.ActivationSpec; import javax.resource.spi.BootstrapContext; import javax.resource.spi.ResourceAdapter; import javax.resource.spi.ResourceAdapterInternalException; -import javax.resource.spi.endpoint.MessageEndpoint; import javax.resource.spi.endpoint.MessageEndpointFactory; import javax.transaction.xa.XAResource; -import com.idcanet.foei.server.FoeiContextManagerFactory; - /** * * @@ -52,11 +52,14 @@ public class FoeiResourceAdapter implements ResourceAdapter { private BootstrapContext bootstrapContext = null; + private Map ejbs = null; + /** * @see javax.resource.spi.ResourceAdapter#start(javax.resource.spi.BootstrapContext) */ public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException { logger.info("Starting FoeiResourceAdapter"); + ejbs = new HashMap(5); this.bootstrapContext=bootstrapContext; } @@ -65,12 +68,8 @@ public class FoeiResourceAdapter implements ResourceAdapter { */ public void stop() { logger.info("Stopping FoeiResourceAdapter"); - try { - FoeiContextManagerFactory.getFoeiContextManager().destroyAll(); - } catch (Exception e) { - logger.log(Level.WARNING,"Error while shutdowning Foei: "+e.getMessage(),e); - throw new RuntimeException(e); - } + ejbs.clear(); + bootstrapContext=null; } /** @@ -84,27 +83,21 @@ public class FoeiResourceAdapter implements ResourceAdapter { * @see javax.resource.spi.ResourceAdapter#endpointActivation(javax.resource.spi.endpoint.MessageEndpointFactory, javax.resource.spi.ActivationSpec) */ public void endpointActivation(MessageEndpointFactory endPointFactory,ActivationSpec spec) throws ResourceException { - FoeiActivationSpec fac = (FoeiActivationSpec)spec; - - MessageEndpoint endPoint = endPointFactory.createEndpoint(null); - endPoint.release(); - - //endPoint. - - fac.getBeanName(); - // reg bean to foei context + logger.info("Activation of: "+fac.getFoeiBeanName()); + SpecBean s = new SpecBean(); + s.messageEndpointFactory=endPointFactory; + s.foeiActivationSpec=fac; + ejbs.put(fac.getFoeiBeanName(),s); } /** * @see javax.resource.spi.ResourceAdapter#endpointDeactivation(javax.resource.spi.endpoint.MessageEndpointFactory, javax.resource.spi.ActivationSpec) */ public void endpointDeactivation(MessageEndpointFactory endPointFactory,ActivationSpec spec) { - //FoeiActivationSpec fac = (FoeiActivationSpec)spec; - - //for (FoeiProcess proc:foeiContext.getFoeiProcessManager().getFoeiProcesses()) { - // proc.removeEventObject(fac.getBeanName()); - //} + FoeiActivationSpec fac = (FoeiActivationSpec)spec; + logger.info("Deactivation of "+fac.getFoeiBeanName()); + ejbs.remove(fac.getFoeiBeanName()); } /** @@ -120,4 +113,23 @@ public class FoeiResourceAdapter implements ResourceAdapter { public void setBootstrapContext(BootstrapContext bootstrapContext) { this.bootstrapContext = bootstrapContext; } + + public List getEJBFoeiBeanNames() { + return new ArrayList(ejbs.keySet()); + } + + public FoeiActivationSpec getFoeiActivationSpec(String name) { + SpecBean s = ejbs.get(name); + return s.foeiActivationSpec; + } + + public MessageEndpointFactory getMessageEndpointFactory(String name) { + SpecBean s = ejbs.get(name); + return s.messageEndpointFactory; + } + + private class SpecBean { + FoeiActivationSpec foeiActivationSpec; + MessageEndpointFactory messageEndpointFactory; + } }