[svn r331] made the SPI interface also work.
This commit is contained in:
parent
46f1863f05
commit
64ca1c8f3a
|
@ -62,11 +62,11 @@ should not be interpreted as representing official policies, either expressed or
|
||||||
<inbound-resourceadapter>
|
<inbound-resourceadapter>
|
||||||
<messageadapter>
|
<messageadapter>
|
||||||
<messagelistener>
|
<messagelistener>
|
||||||
<messagelistener-type>com.idcanet.foei.event.EventInput</messagelistener-type>
|
<messagelistener-type>com.idcanet.foei.ee.jca.spi.EJBFoeiBean</messagelistener-type>
|
||||||
<activationspec>
|
<activationspec>
|
||||||
<activationspec-class>com.idcanet.foei.ee.jca.spi.FoeiActivationSpec</activationspec-class>
|
<activationspec-class>com.idcanet.foei.ee.jca.spi.FoeiActivationSpec</activationspec-class>
|
||||||
<required-config-property>
|
<required-config-property>
|
||||||
<config-property-name>beanName</config-property-name>
|
<config-property-name>foeiBeanName</config-property-name>
|
||||||
</required-config-property>
|
</required-config-property>
|
||||||
</activationspec>
|
</activationspec>
|
||||||
</messagelistener>
|
</messagelistener>
|
||||||
|
|
42
src/com/idcanet/foei/core/FoeiProcessListener.java
Normal file
42
src/com/idcanet/foei/core/FoeiProcessListener.java
Normal file
|
@ -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.<br/>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Willem Cazander
|
||||||
|
* @version 1.0 Apr 26, 2008
|
||||||
|
*/
|
||||||
|
public interface FoeiProcessListener {
|
||||||
|
|
||||||
|
public void foeiProcessCreated(FoeiProcess process);
|
||||||
|
|
||||||
|
public void foeiProcessDestroyed(FoeiProcess process);
|
||||||
|
|
||||||
|
}
|
|
@ -63,4 +63,8 @@ public interface FoeiProcessManager {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Collection<FoeiProcess> getFoeiProcesses();
|
public Collection<FoeiProcess> getFoeiProcesses();
|
||||||
|
|
||||||
|
public void addFoeiProcessListener(FoeiProcessListener foeiProcessListener);
|
||||||
|
|
||||||
|
public void removeFoeiProcessListener(FoeiProcessListener foeiProcessListener);
|
||||||
}
|
}
|
|
@ -28,11 +28,14 @@ package com.idcanet.foei.core.impl;
|
||||||
|
|
||||||
import com.idcanet.foei.core.FoeiContext;
|
import com.idcanet.foei.core.FoeiContext;
|
||||||
import com.idcanet.foei.core.FoeiProcess;
|
import com.idcanet.foei.core.FoeiProcess;
|
||||||
|
import com.idcanet.foei.core.FoeiProcessListener;
|
||||||
import com.idcanet.foei.core.FoeiProcessManager;
|
import com.idcanet.foei.core.FoeiProcessManager;
|
||||||
import com.idcanet.foei.core.ObjectBindingsManager;
|
import com.idcanet.foei.core.ObjectBindingsManager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
@ -53,12 +56,15 @@ public class FoeiProcessManagerImpl implements FoeiProcessManager {
|
||||||
/** The logger to log to. */
|
/** The logger to log to. */
|
||||||
private Logger logger = null;
|
private Logger logger = null;
|
||||||
|
|
||||||
|
private List<FoeiProcessListener> foeiProcessListeners = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an FoeiProcessManagerImpl
|
* Creates an FoeiProcessManagerImpl
|
||||||
*/
|
*/
|
||||||
public FoeiProcessManagerImpl() {
|
public FoeiProcessManagerImpl() {
|
||||||
logger = Logger.getLogger(FoeiProcessManagerImpl.class.getName());
|
logger = Logger.getLogger(FoeiProcessManagerImpl.class.getName());
|
||||||
foeiProcesses = new HashMap<String,FoeiProcess>(5);
|
foeiProcesses = new HashMap<String,FoeiProcess>(5);
|
||||||
|
foeiProcessListeners = new ArrayList<FoeiProcessListener>(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,6 +84,10 @@ public class FoeiProcessManagerImpl implements FoeiProcessManager {
|
||||||
synchronized (foeiProcesses) {
|
synchronized (foeiProcesses) {
|
||||||
foeiProcesses.put(fp.getName(),fp);
|
foeiProcesses.put(fp.getName(),fp);
|
||||||
}
|
}
|
||||||
|
for (FoeiProcessListener l:foeiProcessListeners) {
|
||||||
|
l.foeiProcessCreated(fp);
|
||||||
|
}
|
||||||
|
|
||||||
logger.finer("FoeiProcess created and added total processes: "+foeiProcesses.size());
|
logger.finer("FoeiProcess created and added total processes: "+foeiProcesses.size());
|
||||||
return fp;
|
return fp;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -98,6 +108,9 @@ public class FoeiProcessManagerImpl implements FoeiProcessManager {
|
||||||
synchronized (foeiProcesses) {
|
synchronized (foeiProcesses) {
|
||||||
foeiProcesses.remove(p.getName());
|
foeiProcesses.remove(p.getName());
|
||||||
}
|
}
|
||||||
|
for (FoeiProcessListener l:foeiProcessListeners) {
|
||||||
|
l.foeiProcessDestroyed(p);
|
||||||
|
}
|
||||||
logger.finer("FoeiProcess destroyed total processes: "+foeiProcesses.size());
|
logger.finer("FoeiProcess destroyed total processes: "+foeiProcesses.size());
|
||||||
try {
|
try {
|
||||||
p.getFoeiContext().getEventObjectContext().destroySubcontext(p.getName());
|
p.getFoeiContext().getEventObjectContext().destroySubcontext(p.getName());
|
||||||
|
@ -122,4 +135,18 @@ public class FoeiProcessManagerImpl implements FoeiProcessManager {
|
||||||
public Collection<FoeiProcess> getFoeiProcesses() {
|
public Collection<FoeiProcess> getFoeiProcesses() {
|
||||||
return foeiProcesses.values();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
85
src/com/idcanet/foei/ee/jca/cci/EJBFoeiProcessListener.java
Normal file
85
src/com/idcanet/foei/ee/jca/cci/EJBFoeiProcessListener.java
Normal file
|
@ -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.<br/>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @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) {
|
||||||
|
}
|
||||||
|
}
|
|
@ -86,8 +86,13 @@ public class FoeiManagedConnectionFactory implements ManagedConnectionFactory,Re
|
||||||
Map<String,String> properties = new HashMap<String,String>(0);
|
Map<String,String> properties = new HashMap<String,String>(0);
|
||||||
try {
|
try {
|
||||||
objectContext = FoeiConfiguratorImpl.newContext(properties);
|
objectContext = FoeiConfiguratorImpl.newContext(properties);
|
||||||
eventExecutorManager = new JCAEventExecutorManager((FoeiResourceAdapter)getResourceAdapter());
|
//eventExecutorManager = new JCAEventExecutorManager((FoeiResourceAdapter)getResourceAdapter());
|
||||||
|
eventExecutorManager = FoeiConfiguratorImpl.newEventExecutorManager(properties);
|
||||||
foeiProcessManager = FoeiConfiguratorImpl.newFoeiProcessManager(properties);
|
foeiProcessManager = FoeiConfiguratorImpl.newFoeiProcessManager(properties);
|
||||||
|
|
||||||
|
// inject ejb beans per process
|
||||||
|
foeiProcessManager.addFoeiProcessListener(new EJBFoeiProcessListener((FoeiResourceAdapter)getResourceAdapter()));
|
||||||
|
|
||||||
FoeiConfiguratorImpl.loadEventThreadListeners(properties,eventExecutorManager);
|
FoeiConfiguratorImpl.loadEventThreadListeners(properties,eventExecutorManager);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ResourceException("Error while building childs objects:",e);
|
throw new ResourceException("Error while building childs objects:",e);
|
||||||
|
|
45
src/com/idcanet/foei/ee/jca/spi/EJBFoeiBean.java
Normal file
45
src/com/idcanet/foei/ee/jca/spi/EJBFoeiBean.java
Normal file
|
@ -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.<br/>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @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;
|
||||||
|
}
|
|
@ -45,18 +45,42 @@ public class FoeiActivationSpec implements ActivationSpec, Serializable {
|
||||||
/** The resource adapter */
|
/** The resource adapter */
|
||||||
private transient ResourceAdapter resourceAdapter = null;
|
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()
|
* @see javax.resource.spi.ActivationSpec#validate()
|
||||||
*/
|
*/
|
||||||
public void validate() throws InvalidPropertyException {
|
public void validate() throws InvalidPropertyException {
|
||||||
if (beanName==null) {
|
if (foeiBeanName==null) {
|
||||||
throw new InvalidPropertyException("beanName is null,please set beanName property.");
|
throw new InvalidPropertyException("foeiBeanName is null,please set foeiBeanName property.");
|
||||||
}
|
}
|
||||||
if (beanName.isEmpty()) {
|
if (foeiBeanName.isEmpty()) {
|
||||||
throw new InvalidPropertyException("beanName is empty,please set beanName property.");
|
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() {
|
public String getFoeiBeanName() {
|
||||||
return beanName;
|
return foeiBeanName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param beanName the beanName to set
|
* @param foeiBeanName the foeiBeanName to set
|
||||||
*/
|
*/
|
||||||
public void setBeanName(String beanName) {
|
public void setFoeiBeanName(String foeiBeanName) {
|
||||||
this.beanName = beanName;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -29,35 +29,85 @@ package com.idcanet.foei.ee.jca.spi;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.resource.spi.endpoint.MessageEndpoint;
|
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.EventPort;
|
||||||
import com.idcanet.foei.event.IllegalEventPortNameException;
|
import com.idcanet.foei.event.IllegalEventPortNameException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Wrappers the ejb bean into the foei executing context.
|
||||||
*
|
*
|
||||||
* @author Willem Cazander
|
* @author Willem Cazander
|
||||||
* @version 1.0 Apr 19, 2008
|
* @version 1.0 Apr 19, 2008
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class FoeiEventWrapper extends AbstractEventInput {
|
public class FoeiEventWrapper extends AbstractEventObject {
|
||||||
|
|
||||||
private Logger logger = Logger.getLogger(FoeiEventWrapper.class.getName());
|
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)
|
* @see com.idcanet.foei.event.AbstractEventInput#doEvent(com.idcanet.foei.event.EventPort, java.lang.Object)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doEvent(EventPort eventPort, Object object) throws IllegalEventPortNameException {
|
public void doEvent(EventPort eventPort, Object object) throws IllegalEventPortNameException {
|
||||||
MessageEndpoint endpoint = null;
|
MessageEndpoint endpoint = null;
|
||||||
//MessageEndpointFactory endpointFactory = null; //(MessageEndpointFactory)"endpointFactory";
|
try {
|
||||||
//endpoint = endpointFactory.createEndpoint(null);
|
endpoint = endpointFactory.createEndpoint(null); // creates new EJB3 bean instance !!
|
||||||
if (endpoint != null) {
|
if (endpoint != null) {
|
||||||
AbstractEventInput input = (AbstractEventInput) endpoint;
|
EJBFoeiBean input = (EJBFoeiBean) endpoint;
|
||||||
input.doEvent(eventPort, object);
|
|
||||||
} else {
|
// mmm needed ?
|
||||||
logger.warning("MessageEndPoint is null.");
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -26,7 +26,10 @@
|
||||||
|
|
||||||
package com.idcanet.foei.ee.jca.spi;
|
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 java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.resource.ResourceException;
|
import javax.resource.ResourceException;
|
||||||
|
@ -34,12 +37,9 @@ import javax.resource.spi.ActivationSpec;
|
||||||
import javax.resource.spi.BootstrapContext;
|
import javax.resource.spi.BootstrapContext;
|
||||||
import javax.resource.spi.ResourceAdapter;
|
import javax.resource.spi.ResourceAdapter;
|
||||||
import javax.resource.spi.ResourceAdapterInternalException;
|
import javax.resource.spi.ResourceAdapterInternalException;
|
||||||
import javax.resource.spi.endpoint.MessageEndpoint;
|
|
||||||
import javax.resource.spi.endpoint.MessageEndpointFactory;
|
import javax.resource.spi.endpoint.MessageEndpointFactory;
|
||||||
import javax.transaction.xa.XAResource;
|
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 BootstrapContext bootstrapContext = null;
|
||||||
|
|
||||||
|
private Map<String,SpecBean> ejbs = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see javax.resource.spi.ResourceAdapter#start(javax.resource.spi.BootstrapContext)
|
* @see javax.resource.spi.ResourceAdapter#start(javax.resource.spi.BootstrapContext)
|
||||||
*/
|
*/
|
||||||
public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException {
|
public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException {
|
||||||
logger.info("Starting FoeiResourceAdapter");
|
logger.info("Starting FoeiResourceAdapter");
|
||||||
|
ejbs = new HashMap<String,SpecBean>(5);
|
||||||
this.bootstrapContext=bootstrapContext;
|
this.bootstrapContext=bootstrapContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,12 +68,8 @@ public class FoeiResourceAdapter implements ResourceAdapter {
|
||||||
*/
|
*/
|
||||||
public void stop() {
|
public void stop() {
|
||||||
logger.info("Stopping FoeiResourceAdapter");
|
logger.info("Stopping FoeiResourceAdapter");
|
||||||
try {
|
ejbs.clear();
|
||||||
FoeiContextManagerFactory.getFoeiContextManager().destroyAll();
|
bootstrapContext=null;
|
||||||
} catch (Exception e) {
|
|
||||||
logger.log(Level.WARNING,"Error while shutdowning Foei: "+e.getMessage(),e);
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,27 +83,21 @@ public class FoeiResourceAdapter implements ResourceAdapter {
|
||||||
* @see javax.resource.spi.ResourceAdapter#endpointActivation(javax.resource.spi.endpoint.MessageEndpointFactory, javax.resource.spi.ActivationSpec)
|
* @see javax.resource.spi.ResourceAdapter#endpointActivation(javax.resource.spi.endpoint.MessageEndpointFactory, javax.resource.spi.ActivationSpec)
|
||||||
*/
|
*/
|
||||||
public void endpointActivation(MessageEndpointFactory endPointFactory,ActivationSpec spec) throws ResourceException {
|
public void endpointActivation(MessageEndpointFactory endPointFactory,ActivationSpec spec) throws ResourceException {
|
||||||
|
|
||||||
FoeiActivationSpec fac = (FoeiActivationSpec)spec;
|
FoeiActivationSpec fac = (FoeiActivationSpec)spec;
|
||||||
|
logger.info("Activation of: "+fac.getFoeiBeanName());
|
||||||
MessageEndpoint endPoint = endPointFactory.createEndpoint(null);
|
SpecBean s = new SpecBean();
|
||||||
endPoint.release();
|
s.messageEndpointFactory=endPointFactory;
|
||||||
|
s.foeiActivationSpec=fac;
|
||||||
//endPoint.
|
ejbs.put(fac.getFoeiBeanName(),s);
|
||||||
|
|
||||||
fac.getBeanName();
|
|
||||||
// reg bean to foei context
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see javax.resource.spi.ResourceAdapter#endpointDeactivation(javax.resource.spi.endpoint.MessageEndpointFactory, javax.resource.spi.ActivationSpec)
|
* @see javax.resource.spi.ResourceAdapter#endpointDeactivation(javax.resource.spi.endpoint.MessageEndpointFactory, javax.resource.spi.ActivationSpec)
|
||||||
*/
|
*/
|
||||||
public void endpointDeactivation(MessageEndpointFactory endPointFactory,ActivationSpec spec) {
|
public void endpointDeactivation(MessageEndpointFactory endPointFactory,ActivationSpec spec) {
|
||||||
//FoeiActivationSpec fac = (FoeiActivationSpec)spec;
|
FoeiActivationSpec fac = (FoeiActivationSpec)spec;
|
||||||
|
logger.info("Deactivation of "+fac.getFoeiBeanName());
|
||||||
//for (FoeiProcess proc:foeiContext.getFoeiProcessManager().getFoeiProcesses()) {
|
ejbs.remove(fac.getFoeiBeanName());
|
||||||
// proc.removeEventObject(fac.getBeanName());
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,4 +113,23 @@ public class FoeiResourceAdapter implements ResourceAdapter {
|
||||||
public void setBootstrapContext(BootstrapContext bootstrapContext) {
|
public void setBootstrapContext(BootstrapContext bootstrapContext) {
|
||||||
this.bootstrapContext = bootstrapContext;
|
this.bootstrapContext = bootstrapContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getEJBFoeiBeanNames() {
|
||||||
|
return new ArrayList<String>(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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue