From 53855d8aae5e4fa640d071e6ab4c5016fa89d35b Mon Sep 17 00:00:00 2001 From: willemc Date: Sat, 26 Apr 2008 19:53:15 +0200 Subject: [PATCH] [svn r337] removed some bugs, and made send obj from ejb work and fixed connection problem. --- .../components/lang/DestroyFoeiProcess.java | 9 ++- .../foei/core/ObjectBindingsManager.java | 14 +---- .../foei/core/impl/EventExecutorImpl.java | 58 ++++++------------- .../core/impl/EventExecutorManagerImpl.java | 12 +--- .../core/impl/EventExecutorThreadFactory.java | 6 +- .../foei/core/impl/FoeiProcessImpl.java | 7 --- .../core/impl/FoeiProcessManagerImpl.java | 6 +- .../core/impl/ObjectBindingsManagerImpl.java | 43 +++++--------- .../ee/jca/cci/FoeiManagedConnection.java | 2 + .../jca/cci/FoeiManagedConnectionFactory.java | 1 - .../idcanet/foei/ee/jca/spi/EJBFoeiBean.java | 2 +- .../foei/ee/jca/spi/FoeiEventWrapper.java | 2 +- tests/com/idcanet/foei/SimpleFoeiTests.java | 1 - 13 files changed, 55 insertions(+), 108 deletions(-) diff --git a/src/com/idcanet/foei/components/lang/DestroyFoeiProcess.java b/src/com/idcanet/foei/components/lang/DestroyFoeiProcess.java index 2d52428..72377d9 100644 --- a/src/com/idcanet/foei/components/lang/DestroyFoeiProcess.java +++ b/src/com/idcanet/foei/components/lang/DestroyFoeiProcess.java @@ -82,7 +82,14 @@ public class DestroyFoeiProcess extends AbstractEventInput { FoeiProcess process = FoeiProcessFactory.getFoeiProcess(); if (process.getWorkQueue().isEmpty()==false) { - //return; + logger.info("WorkQueue not empty sleeping a bit and sending retrigger myself q="+process.getWorkQueue().size()+" for proc: "+process.getName()); + try { + Thread.sleep(delayTime+500); // add some minual d + } catch (Exception e) { + logger.log(Level.WARNING,"Error sleeping: "+e.getMessage(),e); + } + process.executeEvent(getInputPort(EventPort.INPUT), "null"); + return; } if(delayTime!=null) { diff --git a/src/com/idcanet/foei/core/ObjectBindingsManager.java b/src/com/idcanet/foei/core/ObjectBindingsManager.java index 48e220e..69c42df 100644 --- a/src/com/idcanet/foei/core/ObjectBindingsManager.java +++ b/src/com/idcanet/foei/core/ObjectBindingsManager.java @@ -36,8 +36,8 @@ import java.util.List; * @author Willem Cazander * @version 1.0 1/05/2005 */ -public interface ObjectBindingsManager -{ +public interface ObjectBindingsManager { + /** * Adds an binding from the input to the output EventPort. * @param outputPort The output EventPort @@ -58,15 +58,7 @@ public interface ObjectBindingsManager * @return Returns an List of the binded EventPorts */ public List getBindings(EventPort eventPort); - - /** - * Gets the bindings of an EventPort of InputPorts - * @param eventPort The EventPort to retreive the bindings which should be an OutputPort - * @return Returns an List of the binded EventPorts - */ - public List getBindingsInputPorts(EventPort eventPort); - - + /** * Returns the bindings in an xml format to render with dotty. * @return diff --git a/src/com/idcanet/foei/core/impl/EventExecutorImpl.java b/src/com/idcanet/foei/core/impl/EventExecutorImpl.java index 69bc00d..be1b041 100644 --- a/src/com/idcanet/foei/core/impl/EventExecutorImpl.java +++ b/src/com/idcanet/foei/core/impl/EventExecutorImpl.java @@ -49,10 +49,7 @@ public class EventExecutorImpl implements EventExecutor { /** The logger to log to. */ private Logger logger = null; - /** The event obect. */ - //private Object eventObject = null; - /** The eventport */ - //private EventPort eventPort = null; + /** The foei process to execute for */ private FoeiProcess foeiProcess = null; /** True when ready */ private volatile boolean ready = false; @@ -69,22 +66,7 @@ public class EventExecutorImpl implements EventExecutor { */ public void setFoeiProcess(FoeiProcess foeiProcess) { this.foeiProcess=foeiProcess; - //this.eventObject=eventObject; - //ready = false; } - - /** - * @see EventExecutor#setEventPort(EventPort) - */ - /* - public void setEventPort(EventPort eventPort) { - if(eventPort==null) { - throw new NullPointerException("EventPort may not be null."); - } - this.eventPort=eventPort; - ready = false; - } - */ /** * @see EventExecutor#isReady() @@ -104,7 +86,6 @@ public class EventExecutorImpl implements EventExecutor { ready = false; int processed = 0; try { - //FoeiProcess foeiProcess = FoeiProcessFactory.getFoeiProcess(); FoeiProcessFactory.bindFoeiProcess(foeiProcess); FoeiPortMessage msg = foeiProcess.getWorkQueue().poll(); @@ -112,16 +93,21 @@ public class EventExecutorImpl implements EventExecutor { process(msg); processed++; msg = foeiProcess.getWorkQueue().poll(); - } - Thread.sleep(200); - msg = foeiProcess.getWorkQueue().poll(); - while (msg!=null) { - process(msg); - processed++; - msg = foeiProcess.getWorkQueue().poll(); - } - - + + // try 3 times to get new work, if not found then exit, EventExecutorManagerImpl work auto create new EventExecutor on new work. + if (msg==null) { + Thread.sleep(200); + msg = foeiProcess.getWorkQueue().poll(); + } + if (msg==null) { + Thread.sleep(200); + msg = foeiProcess.getWorkQueue().poll(); + } + if (msg==null) { + Thread.sleep(200); + msg = foeiProcess.getWorkQueue().poll(); + } + } } catch (Exception e) { logger.log(Level.WARNING,"Error while Executing Event",e); } finally { @@ -145,23 +131,15 @@ public class EventExecutorImpl implements EventExecutor { if(eventPort.getEventPortType()==EventPortType.output) { eventPort.addEventsPassed(); // inc output port - // uses the faster routine to get bindings ..., - //List bindings = foeiProcess.getBindings(eventPort); - List bindings = foeiProcess.getBindingsInputPorts(eventPort); - + List bindings = foeiProcess.getBindings(eventPort); for (int i=0;i getBindingsInputPorts(EventPort eventPort) { - return getObjectBindingsManager().getBindingsInputPorts(eventPort); - } - /** * @see com.idcanet.foei.core.ObjectBindingsManager#getBindingsAsXML() */ diff --git a/src/com/idcanet/foei/core/impl/FoeiProcessManagerImpl.java b/src/com/idcanet/foei/core/impl/FoeiProcessManagerImpl.java index 7034497..7b735e7 100644 --- a/src/com/idcanet/foei/core/impl/FoeiProcessManagerImpl.java +++ b/src/com/idcanet/foei/core/impl/FoeiProcessManagerImpl.java @@ -108,9 +108,9 @@ public class FoeiProcessManagerImpl implements FoeiProcessManager { synchronized (foeiProcesses) { foeiProcesses.remove(p.getName()); } - for (FoeiProcessListener l:foeiProcessListeners) { - l.foeiProcessDestroyed(p); - } + for (FoeiProcessListener l:foeiProcessListeners) { + l.foeiProcessDestroyed(p); + } logger.finer("FoeiProcess destroyed total processes: "+foeiProcesses.size()); try { p.getFoeiContext().getEventObjectContext().destroySubcontext(p.getName()); diff --git a/src/com/idcanet/foei/core/impl/ObjectBindingsManagerImpl.java b/src/com/idcanet/foei/core/impl/ObjectBindingsManagerImpl.java index 598f797..d192dde 100644 --- a/src/com/idcanet/foei/core/impl/ObjectBindingsManagerImpl.java +++ b/src/com/idcanet/foei/core/impl/ObjectBindingsManagerImpl.java @@ -147,36 +147,21 @@ public class ObjectBindingsManagerImpl implements ObjectBindingsManager { if(eventPort==null) { throw new NullPointerException("eventPort may not be null."); } - List result = new ArrayList(6); - List inputPorts = bindingsInput.get(eventPort); - List outputPorts = bindingsOutput.get(eventPort); - if(inputPorts!=null) { - result.addAll(inputPorts); + if (EventPortType.output.equals(eventPort.getEventPortType())) { + List inputPorts = bindingsOutput.get(eventPort); + if(inputPorts!=null) { + return inputPorts; + } + List result = new ArrayList(0); + return result; + } else { + List outputPorts = bindingsInput.get(eventPort); + if(outputPorts!=null) { + return outputPorts; + } + List result = new ArrayList(0); + return result; } - if(outputPorts!=null) { - result.addAll(outputPorts); - } - return result; - } - - /** - * Gets the bindings of an EventPort - * @param eventPort The EventPort to retreive the bindings. - * @return Returns an List of the binded EventPorts - */ - public List getBindingsInputPorts(EventPort eventPort) { - if(eventPort==null) { - throw new NullPointerException("eventPort may not be null."); - } - if (EventPortType.output.equals(eventPort.getEventPortType())==false) { - throw new IllegalArgumentException("eventPort should be output port."); - } - List inputPorts = bindingsOutput.get(eventPort); - if(inputPorts!=null) { - return inputPorts; - } - List result = new ArrayList(0); - return result; } /** diff --git a/src/com/idcanet/foei/ee/jca/cci/FoeiManagedConnection.java b/src/com/idcanet/foei/ee/jca/cci/FoeiManagedConnection.java index 6d36fba..2d9f920 100644 --- a/src/com/idcanet/foei/ee/jca/cci/FoeiManagedConnection.java +++ b/src/com/idcanet/foei/ee/jca/cci/FoeiManagedConnection.java @@ -100,6 +100,7 @@ public class FoeiManagedConnection implements ManagedConnection { synchronized (this.listeners) { listeners = null; } + foeiContext.destroy(); foeiContext = null; } @@ -220,6 +221,7 @@ public class FoeiManagedConnection implements ManagedConnection { */ public void close(FoeiConnectionImpl con) { ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED); + event.setConnectionHandle(con); synchronized (this.listeners) { Iterator itr = listeners.iterator(); while (itr.hasNext()) { diff --git a/src/com/idcanet/foei/ee/jca/cci/FoeiManagedConnectionFactory.java b/src/com/idcanet/foei/ee/jca/cci/FoeiManagedConnectionFactory.java index da206dc..ef0229e 100644 --- a/src/com/idcanet/foei/ee/jca/cci/FoeiManagedConnectionFactory.java +++ b/src/com/idcanet/foei/ee/jca/cci/FoeiManagedConnectionFactory.java @@ -49,7 +49,6 @@ import com.idcanet.foei.core.FoeiProcessManager; import com.idcanet.foei.core.impl.FoeiConfiguratorImpl; import com.idcanet.foei.core.impl.FoeiContextImpl; import com.idcanet.foei.ee.jca.spi.FoeiResourceAdapter; -import com.idcanet.foei.ee.jca.spi.JCAEventExecutorManager; /** * diff --git a/src/com/idcanet/foei/ee/jca/spi/EJBFoeiBean.java b/src/com/idcanet/foei/ee/jca/spi/EJBFoeiBean.java index 57cdd60..ad403f2 100644 --- a/src/com/idcanet/foei/ee/jca/spi/EJBFoeiBean.java +++ b/src/com/idcanet/foei/ee/jca/spi/EJBFoeiBean.java @@ -41,5 +41,5 @@ import com.idcanet.foei.event.IllegalEventPortNameException; */ public interface EJBFoeiBean extends EventInput,EventOutput { - public void doEvent(FoeiProcess process,EventPort eventPort,Object object) throws IllegalEventPortNameException; + public void doEvent(FoeiProcess process,FoeiEventWrapper wrapper,EventPort eventPort,Object object) throws IllegalEventPortNameException; } \ 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 451f97b..68057ad 100644 --- a/src/com/idcanet/foei/ee/jca/spi/FoeiEventWrapper.java +++ b/src/com/idcanet/foei/ee/jca/spi/FoeiEventWrapper.java @@ -98,7 +98,7 @@ public class FoeiEventWrapper extends AbstractEventObject { // mmm needed ? // yes for normaly equals .. EventPort port = input.getInputPort(eventPort.getName()); - input.doEvent(foeiProcess,port, object); + input.doEvent(foeiProcess,this,port, object); } else { logger.warning("MessageEndPoint is null."); } diff --git a/tests/com/idcanet/foei/SimpleFoeiTests.java b/tests/com/idcanet/foei/SimpleFoeiTests.java index b40693f..bd29205 100644 --- a/tests/com/idcanet/foei/SimpleFoeiTests.java +++ b/tests/com/idcanet/foei/SimpleFoeiTests.java @@ -32,7 +32,6 @@ import java.util.Properties; import com.idcanet.foei.components.lang.DummyOutputPort; import com.idcanet.foei.components.lang.Filter; -import com.idcanet.foei.core.FoeiConfigurator; import com.idcanet.foei.core.FoeiContext; import com.idcanet.foei.core.FoeiProcess; import com.idcanet.foei.event.AbstractEventInput;