From 7c57017fff80850c4a43237d63890bb24ffbee03 Mon Sep 17 00:00:00 2001 From: willemc Date: Thu, 28 Feb 2008 01:42:11 +0100 Subject: [PATCH] [svn r325] some cleaning, adding speed improvements !!, and started on junit tests. --- .classpath | 1 + doc/todo.txt | 8 +- .../idcanet/foei/components/lang/Filter.java | 5 +- .../foei/components/lang/GetBeanProperty.java | 2 +- .../components/lang/ObjectChangedBuffer.java | 4 +- .../idcanet/foei/core/FoeiConfigurator.java | 2 +- .../foei/core/ObjectBindingsManager.java | 7 + .../foei/core/impl/EventExecutorImpl.java | 12 +- .../core/impl/EventExecutorManagerImpl.java | 2 +- .../foei/core/impl/FoeiConfiguratorImpl.java | 2 +- .../foei/core/impl/FoeiProcessImpl.java | 7 + .../core/impl/ObjectBindingsManagerImpl.java | 22 ++- .../foei/core/x4o/ObjectBindingElement.java | 2 - .../foei/event/AbstractEventInput.java | 2 +- .../foei/event/AbstractEventObject.java | 6 +- .../foei/event/AbstractEventOutput.java | 2 +- src/com/idcanet/foei/event/EventPort.java | 12 +- src/com/idcanet/foei/event/EventPortType.java | 11 +- .../foei/utils/jdbc/ConnectionFactory.java | 56 ------ .../foei/utils/jdbc/ConnectionProvider.java | 55 ------ .../utils/jdbc/ConnectionProviderManager.java | 115 ------------ .../utils/jdbc/JndiDataSourceProvider.java | 163 ------------------ src/com/idcanet/foei/utils/jdbc/package.html | 61 ------- .../foei/utils/jndi/ContextListWriter.java | 6 +- .../test-foei-config.xml} | 0 .../test-foei.properties} | 2 +- tests/com/idcanet/foei/SimpleFoeiTests.java | 157 ++++++++++++++++- .../idcanet/foei/TestEventThreadListener.java | 25 +++ 28 files changed, 266 insertions(+), 483 deletions(-) delete mode 100644 src/com/idcanet/foei/utils/jdbc/ConnectionFactory.java delete mode 100644 src/com/idcanet/foei/utils/jdbc/ConnectionProvider.java delete mode 100644 src/com/idcanet/foei/utils/jdbc/ConnectionProviderManager.java delete mode 100644 src/com/idcanet/foei/utils/jdbc/JndiDataSourceProvider.java delete mode 100644 src/com/idcanet/foei/utils/jdbc/package.html rename tests/{com/META-INF/foei-config.xml => META-INF/test-foei-config.xml} (100%) rename tests/{com/META-INF/foei.properties => META-INF/test-foei.properties} (92%) diff --git a/.classpath b/.classpath index c57e3b4..03744ea 100644 --- a/.classpath +++ b/.classpath @@ -9,5 +9,6 @@ + diff --git a/doc/todo.txt b/doc/todo.txt index d7fc6f4..a1cd25a 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -1,2 +1,8 @@ --- IDCANET x2o TODO list -- +-- IDCANET X4O TODO list -- + +- make J2EE compaitle +- Add annotations for ports +- Make asysc piping faster +- Start implementing JMS interfaces + diff --git a/src/com/idcanet/foei/components/lang/Filter.java b/src/com/idcanet/foei/components/lang/Filter.java index 01cd9af..288702b 100644 --- a/src/com/idcanet/foei/components/lang/Filter.java +++ b/src/com/idcanet/foei/components/lang/Filter.java @@ -33,8 +33,6 @@ import com.idcanet.foei.event.EventPort; import com.idcanet.foei.event.EventPortType; import com.idcanet.foei.event.EventStep; import com.idcanet.foei.event.IllegalEventPortNameException; -import com.idcanet.foei.event.annotations.SetEventPort; -import com.idcanet.foei.event.annotations.SetEventPorts; /** * Fiters the object on the Input port throw all @@ -86,7 +84,8 @@ public class Filter extends AbstractEventObjectStepController @Override public Object processEventSteps(Object object) { Object o = object; - for(EventStep e:getEventSteps()) { + for (int i=0;i bufferedObjects = null; + private Map,Object> bufferedObjects = null; public static final String NO_CHANGE = "noChange"; @@ -41,7 +41,7 @@ public class ObjectChangedBuffer extends AbstractEventObject { addInputPort(EventPort.INPUT); addOutputPort(EventPort.OUTPUT); addOutputPort(NO_CHANGE); - bufferedObjects = Collections.synchronizedMap(new HashMap(2)); + bufferedObjects = Collections.synchronizedMap(new HashMap,Object>(2)); } /** diff --git a/src/com/idcanet/foei/core/FoeiConfigurator.java b/src/com/idcanet/foei/core/FoeiConfigurator.java index b166dea..918d7c0 100644 --- a/src/com/idcanet/foei/core/FoeiConfigurator.java +++ b/src/com/idcanet/foei/core/FoeiConfigurator.java @@ -75,7 +75,7 @@ public interface FoeiConfigurator { static public final String X2O_ROOT_TAG = "foei.x2o_root_tag"; /** The default FoeiConfigurator */ - static public final Class DEFAULT_FOEI_CONFIGURATOR = FoeiConfiguratorImpl.class; + static public final Class DEFAULT_FOEI_CONFIGURATOR = FoeiConfiguratorImpl.class; /** * Starts an FoeiContext diff --git a/src/com/idcanet/foei/core/ObjectBindingsManager.java b/src/com/idcanet/foei/core/ObjectBindingsManager.java index e0075cd..48e220e 100644 --- a/src/com/idcanet/foei/core/ObjectBindingsManager.java +++ b/src/com/idcanet/foei/core/ObjectBindingsManager.java @@ -58,6 +58,13 @@ 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); /** diff --git a/src/com/idcanet/foei/core/impl/EventExecutorImpl.java b/src/com/idcanet/foei/core/impl/EventExecutorImpl.java index 123bbf4..cb9b61b 100644 --- a/src/com/idcanet/foei/core/impl/EventExecutorImpl.java +++ b/src/com/idcanet/foei/core/impl/EventExecutorImpl.java @@ -106,15 +106,19 @@ public class EventExecutorImpl implements EventExecutor { } if(eventPort.getEventPortType()==EventPortType.output) { eventPort.addEventsPassed(); // inc output port - List bindings = foeiProcess.getBindings(eventPort); - for(EventPort port:bindings) { + + // uses the faster routine to get bindings ..., + //List bindings = foeiProcess.getBindings(eventPort); + List bindings = foeiProcess.getBindingsInputPorts(eventPort); + + for (int i=0;i eventThreadListeners = null; /** The class for the EventExecutor */ - private Class eventExecutorClass = null; + private Class eventExecutorClass = null; /** * Creates an EventExecutorManagerImpl ans inits the logger. */ diff --git a/src/com/idcanet/foei/core/impl/FoeiConfiguratorImpl.java b/src/com/idcanet/foei/core/impl/FoeiConfiguratorImpl.java index 44b4c63..34a0e0f 100644 --- a/src/com/idcanet/foei/core/impl/FoeiConfiguratorImpl.java +++ b/src/com/idcanet/foei/core/impl/FoeiConfiguratorImpl.java @@ -224,7 +224,7 @@ public class FoeiConfiguratorImpl implements FoeiConfigurator { * @return * @throws ClassNotFoundException */ - static public Class newEventExecutorClass(Map properties) throws ClassNotFoundException { + static public Class newEventExecutorClass(Map properties) throws ClassNotFoundException { String className = properties.get(FoeiConfigurator.EVENT_EXECUTOR); if(className==null) { return EventExecutorImpl.class; diff --git a/src/com/idcanet/foei/core/impl/FoeiProcessImpl.java b/src/com/idcanet/foei/core/impl/FoeiProcessImpl.java index a92ed4f..8364510 100644 --- a/src/com/idcanet/foei/core/impl/FoeiProcessImpl.java +++ b/src/com/idcanet/foei/core/impl/FoeiProcessImpl.java @@ -170,6 +170,13 @@ public class FoeiProcessImpl implements FoeiProcess { public List getBindings(EventPort eventPort) { return getObjectBindingsManager().getBindings(eventPort); } + + /** + * @see com.idcanet.foei.core.ObjectBindingsManager#getBindingsInputPorts(com.idcanet.foei.event.EventPort) + */ + public List getBindingsInputPorts(EventPort eventPort) { + return getObjectBindingsManager().getBindingsInputPorts(eventPort); + } /** * @see com.idcanet.foei.core.ObjectBindingsManager#getBindingsAsXML() diff --git a/src/com/idcanet/foei/core/impl/ObjectBindingsManagerImpl.java b/src/com/idcanet/foei/core/impl/ObjectBindingsManagerImpl.java index 74252c2..598f797 100644 --- a/src/com/idcanet/foei/core/impl/ObjectBindingsManagerImpl.java +++ b/src/com/idcanet/foei/core/impl/ObjectBindingsManagerImpl.java @@ -147,7 +147,7 @@ public class ObjectBindingsManagerImpl implements ObjectBindingsManager { if(eventPort==null) { throw new NullPointerException("eventPort may not be null."); } - List result = new ArrayList(0); + List result = new ArrayList(6); List inputPorts = bindingsInput.get(eventPort); List outputPorts = bindingsOutput.get(eventPort); if(inputPorts!=null) { @@ -158,6 +158,26 @@ public class ObjectBindingsManagerImpl implements ObjectBindingsManager { } 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; + } /** * Returns the dotty xml bindings diff --git a/src/com/idcanet/foei/core/x4o/ObjectBindingElement.java b/src/com/idcanet/foei/core/x4o/ObjectBindingElement.java index 35bc3ec..b58544c 100644 --- a/src/com/idcanet/foei/core/x4o/ObjectBindingElement.java +++ b/src/com/idcanet/foei/core/x4o/ObjectBindingElement.java @@ -36,8 +36,6 @@ import com.idcanet.foei.event.EventPort; import com.idcanet.x4o.element.AbstractElement; import com.idcanet.x4o.element.ElementException; -import org.xml.sax.Attributes; - /** * * diff --git a/src/com/idcanet/foei/event/AbstractEventInput.java b/src/com/idcanet/foei/event/AbstractEventInput.java index 6ce4353..5895ab3 100644 --- a/src/com/idcanet/foei/event/AbstractEventInput.java +++ b/src/com/idcanet/foei/event/AbstractEventInput.java @@ -64,7 +64,7 @@ abstract public class AbstractEventInput implements EventInput { * @param inputName The inputName of the EventPort * @param inputType The inputClass of the EventPort */ - protected void addInputPort(String inputName,Class inputClass) { + protected void addInputPort(String inputName,Class inputClass) { if(inputName==null) { throw new NullPointerException("inputName may not be null."); } diff --git a/src/com/idcanet/foei/event/AbstractEventObject.java b/src/com/idcanet/foei/event/AbstractEventObject.java index ff438de..e1cd1d1 100644 --- a/src/com/idcanet/foei/event/AbstractEventObject.java +++ b/src/com/idcanet/foei/event/AbstractEventObject.java @@ -39,8 +39,8 @@ import java.util.Map; * @author Willem Cazander * @version 1.0 Aug 17, 2005 */ -abstract public class AbstractEventObject extends AbstractEventOutput implements EventInput -{ +abstract public class AbstractEventObject extends AbstractEventOutput implements EventInput { + /** The input EventPorts */ private Map inputs = null; @@ -61,7 +61,7 @@ abstract public class AbstractEventObject extends AbstractEventOutput implements * @param inputName The inputName of the EventPort * @param inputType The inputType of the EventPort */ - protected void addInputPort(String inputName,Class inputType) { + protected void addInputPort(String inputName,Class inputType) { if(inputName==null) { throw new NullPointerException("inputName may not be null."); } diff --git a/src/com/idcanet/foei/event/AbstractEventOutput.java b/src/com/idcanet/foei/event/AbstractEventOutput.java index a76e47a..27e6259 100644 --- a/src/com/idcanet/foei/event/AbstractEventOutput.java +++ b/src/com/idcanet/foei/event/AbstractEventOutput.java @@ -65,7 +65,7 @@ abstract public class AbstractEventOutput implements EventOutput { * @param outputName The outputName of the EventPort. * @param outputType The output Class type of the EventPort. */ - protected void addOutputPort(String outputName,Class outputType) { + protected void addOutputPort(String outputName,Class outputType) { if(outputName==null) { throw new NullPointerException("outputName may not be null."); } diff --git a/src/com/idcanet/foei/event/EventPort.java b/src/com/idcanet/foei/event/EventPort.java index 0682a48..e89d24d 100644 --- a/src/com/idcanet/foei/event/EventPort.java +++ b/src/com/idcanet/foei/event/EventPort.java @@ -37,17 +37,23 @@ package com.idcanet.foei.event; */ public class EventPort { + /** public type for defining TRUE */ static final public String TRUE = "true"; + /** public type for defining FALSE */ static final public String FALSE = "false"; + /** public type for defining INPUT */ static final public String INPUT = "input"; + /** public type for defining OUTPUT */ static final public String OUTPUT = "output"; + /** public type for defining PASS */ static final public String PASS = "pass"; + /** public type for defining DROP */ static final public String DROP = "drop"; /** The name of the port */ private String name = null; /** The type of Object class which can be handled by the port.*/ - private Class objectType = null; + private Class objectType = null; /** The total number of events this port has had. */ private long eventsPassed = 0; /** The type of event port */ @@ -68,7 +74,7 @@ public class EventPort { * @param name The name of the EventPort. * @param objectType The class type which it accepts. */ - public EventPort(String name,Class objectType,EventPortType eventPortType,Object eventObject) { + public EventPort(String name,Class objectType,EventPortType eventPortType,Object eventObject) { if(name==null) { throw new NullPointerException("name may not be null."); } @@ -107,7 +113,7 @@ public class EventPort { * Returns the class of the object this EventPort handleds. * @return the class of the transfering object. */ - public Class getObjectClass() { + public Class getObjectClass() { return objectType; } diff --git a/src/com/idcanet/foei/event/EventPortType.java b/src/com/idcanet/foei/event/EventPortType.java index 5d98081..fc434a0 100644 --- a/src/com/idcanet/foei/event/EventPortType.java +++ b/src/com/idcanet/foei/event/EventPortType.java @@ -33,7 +33,14 @@ package com.idcanet.foei.event; * @version 1.0 Mar 3, 2006 */ public enum EventPortType { + + /** + * Type for input ports + */ + input, - input, - output; + /** + * Type for output ports + */ + output; } diff --git a/src/com/idcanet/foei/utils/jdbc/ConnectionFactory.java b/src/com/idcanet/foei/utils/jdbc/ConnectionFactory.java deleted file mode 100644 index 788da2f..0000000 --- a/src/com/idcanet/foei/utils/jdbc/ConnectionFactory.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2004-2006 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.utils.jdbc; - -import java.sql.Connection; - -/** - * Java code can get a DB connections here. - * Its retreived from the ConnectionProviderManager. - * - * @author Willem Cazander - * @version 1.0 - */ -public class ConnectionFactory -{ - /** - * Returns a connection by its name - * @param name The name of the connection - * @return Returns the Connection. - */ - static public Connection getConnection(String name) { - return getConnectionProviderManager().getConnection(name); - } - - /** - * Gets the instance of the ConnectionProviderManager. - * @return Returns the ConnectionProviderManager. - */ - static public ConnectionProviderManager getConnectionProviderManager() { - return ConnectionProviderManager.getSharedInstance(); - } -} \ No newline at end of file diff --git a/src/com/idcanet/foei/utils/jdbc/ConnectionProvider.java b/src/com/idcanet/foei/utils/jdbc/ConnectionProvider.java deleted file mode 100644 index 7f34bc8..0000000 --- a/src/com/idcanet/foei/utils/jdbc/ConnectionProvider.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2004-2006 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.utils.jdbc; - -import java.sql.Connection; - -/** - * The ConnectionProvider is an interface which - * lets objects returns a Connection. - * - * We normally registrates an ConnectionProvider to the - * ConnectionProviderManager so objects can use it. - * - * @author Willem Cazander - * @version 1.0 Jan 4, 2006 - */ -public interface ConnectionProvider -{ - /** - * Gets the connection name for which this - * ConnectionProvider handles connections. - * @return Returns the connection name. - */ - public String getConnectionName(); - - /** - * Gets an connection of this ConnectionProvider. - * @return Returns an Connection - */ - public Connection getConnection(); -} \ No newline at end of file diff --git a/src/com/idcanet/foei/utils/jdbc/ConnectionProviderManager.java b/src/com/idcanet/foei/utils/jdbc/ConnectionProviderManager.java deleted file mode 100644 index a943a4d..0000000 --- a/src/com/idcanet/foei/utils/jdbc/ConnectionProviderManager.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2004-2006 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.utils.jdbc; - -import java.sql.Connection; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Logger; - -/** - * Manages the different ConnectionProviders. - * - * @author Willem Cazander - * @version 1.0 Jan 4, 2006 - */ -public class ConnectionProviderManager -{ - /** The logger to log to */ - private Logger logger = null; - /** The map with all connection providers */ - private Map connectionProviders = null; - /** The ConnectionProviderManager instance */ - static private ConnectionProviderManager connectionProviderManager = null; - - static { - try { - connectionProviderManager = new ConnectionProviderManager(); - } catch (Exception e) { - throw new RuntimeException("Error while creating ConnectionProviderManager",e); - } - } - - /** - * Creates an private ConnectionProviderManager - * - */ - private ConnectionProviderManager() { - logger = Logger.getLogger(ConnectionProviderManager.class.getName()); - logger.fine("Creating an ConnectionProviderManager"); - connectionProviders = new HashMap(3); - } - - /** - * Returns the singleton object of the ConnectionProviderManager. - * @return - */ - static public ConnectionProviderManager getSharedInstance() { - return connectionProviderManager; - } - - // ============ END SINGLETON - - /** - * Gets an Connection by its connectionName - * @param connectionName The connection name. - * @return Returns the Connection - */ - public Connection getConnection(String connectionName) { - return getConnectionProvider(connectionName).getConnection(); - } - - /** - * Adds an ConnectionProvider - * @param connectionProvider The ConnectionProvider to add. - */ - public void addConnectionProvider(ConnectionProvider connectionProvider) { - if(connectionProvider==null) { - throw new NullPointerException("connectionProvider may not be null."); - } - logger.fine("Adding ConnnectionProvider for connection: "+connectionProvider.getConnectionName()); - connectionProviders.put(connectionProvider.getConnectionName(),connectionProvider); - } - - /** - * Gets an ConnectionProvider by its connectionName - * @param connectionName The connection name - * @return Returns the ConnectionProvider for this connectionName. - */ - public ConnectionProvider getConnectionProvider(String connectionName) { - return connectionProviders.get(connectionName); - } - - /** - * Gets all ConnectionProviders - * @return Returns all ConnectionProviders. - */ - public Collection getConnectionProviders() { - return connectionProviders.values(); - } -} \ No newline at end of file diff --git a/src/com/idcanet/foei/utils/jdbc/JndiDataSourceProvider.java b/src/com/idcanet/foei/utils/jdbc/JndiDataSourceProvider.java deleted file mode 100644 index 0715a9e..0000000 --- a/src/com/idcanet/foei/utils/jdbc/JndiDataSourceProvider.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright 2004-2006 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.utils.jdbc; - -import java.sql.Connection; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import javax.sql.DataSource; - -/** - * The JndiDataSourceProvider is an ConnectionProvider which gets its connection - * from a jndi context. - * @author Willem Cazander - * @version 1.0 Jan 4, 2006 - */ -public class JndiDataSourceProvider implements ConnectionProvider -{ - /** The context in which database datasources are found. */ - private static final String DATASOURCE_CONTEXT = "java:comp/env/jdbc/"; - /** The connectionName for this Provider */ - private String connectionName = null; - /** The jndi context to search for the dataSource. */ - private String dataSourceContext = null; - /** The logger to log to. */ - private Logger logger = null; - - /** - * Creates an JndiDataSourceProvider and inits the Logger - */ - public JndiDataSourceProvider() { - logger = Logger.getLogger(JndiDataSourceProvider.class.getName()); - } - - /** - * Creates JndiDataSourceProvider and sets its connectionName. - * @param connectionName - */ - public JndiDataSourceProvider(String connectionName) { - this(); - setConnectionName(connectionName); - } - - /** - * Creates an JndiDataSourceProvider and inits the Logger - * @param connectionName The connection name which this provider handles - * @param dataSourceContext The JNDI datasource prefix for getting the DataSource - */ - public JndiDataSourceProvider(String connectionName,String dataSourceContext) { - this(connectionName); - setDataSourceContext(dataSourceContext); - } - - /** - * Gets an DataSource out of the jndi context. - * @param name The name of the datasource in the jndi context. - * @return The datasource. - */ - static public DataSource getDataSource(String name) { - - try { - Context initialContext = new InitialContext(); - if(initialContext == null) { - throw new RuntimeException("Init: Cannot get Initial Context"); - } - DataSource datasource = (DataSource) initialContext.lookup(name); - if(datasource == null) { - throw new RuntimeException("Init: Cannot lookup datasource: '"+name+"'"); - } - return datasource; - } catch (NamingException ex) { - throw new RuntimeException("Init: Cannot get connection " + ex); - } - } - - //========= ConnectionProvider - - /** - * Gets the connection name for which this - * ConnectionProvider handles connections. - * @return Returns the connection name. - * @see ConnectionProvider#getConnectionName() - */ - public String getConnectionName() { - return connectionName; - } - - /** - * Gets an connection of this ConnectionProvider. - * @return Returns an Connection - * @see ConnectionProvider#getConnection() - */ - public Connection getConnection() { - try { - if(dataSourceContext==null) { - dataSourceContext=DATASOURCE_CONTEXT; - } - logger.finest("Trying retreiving DataSource of connectionName="+connectionName); - return getDataSource(dataSourceContext+connectionName).getConnection(); - } catch (Exception e) { - logger.log(Level.WARNING,"Error while getting DataSource",e); - throw new NullPointerException("No datasource"); - } - } - - // ==== set/getter - - /** - * Sets the connectionName. - * @param connectionName The connectionName to set. - */ - public void setConnectionName(String connectionName) { - if(connectionName==null) { - throw new NullPointerException("connectionName may not be null."); - } - logger.finest("setting connectionName="+connectionName); - this.connectionName=connectionName; - } - - /** - * @return Returns the dataSourceContext. - */ - public String getDataSourceContext() { - return dataSourceContext; - } - - /** - * When set to null(default) then - * DATASOURCE_CONTEXT is used. ("java:comp/env/jdbc/") - * @param dataSourceContext The dataSourceContext to set. - */ - public void setDataSourceContext(String dataSourceContext) { - logger.finest("setting dataSourceContext="+dataSourceContext); - this.dataSourceContext = dataSourceContext; - } -} \ No newline at end of file diff --git a/src/com/idcanet/foei/utils/jdbc/package.html b/src/com/idcanet/foei/utils/jdbc/package.html deleted file mode 100644 index 6992623..0000000 --- a/src/com/idcanet/foei/utils/jdbc/package.html +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - -An generic ConnectionProvider with default jndi support.
- -

Package Specification

- -
    -
  • Full J2SE 5 compatible
  • -
  • Small package
  • -
- - -

Related Documentation

- -None. - - - - - \ No newline at end of file diff --git a/src/com/idcanet/foei/utils/jndi/ContextListWriter.java b/src/com/idcanet/foei/utils/jndi/ContextListWriter.java index c771bc3..ce8b502 100644 --- a/src/com/idcanet/foei/utils/jndi/ContextListWriter.java +++ b/src/com/idcanet/foei/utils/jndi/ContextListWriter.java @@ -38,8 +38,8 @@ import java.io.PrintStream; * @author Willem Cazander * @version 1.0 Jan 18, 2006 */ -public class ContextListWriter -{ +public class ContextListWriter { + /** * writes an context tree to the printstream out. * @param out The printstream to which the text line are printed. @@ -52,7 +52,7 @@ public class ContextListWriter return; } try { - NamingEnumeration list = ctx.listBindings(""); + NamingEnumeration list = ctx.listBindings(""); while (list.hasMore()) { Binding item = (Binding)list.next(); String className = item.getClassName(); diff --git a/tests/com/META-INF/foei-config.xml b/tests/META-INF/test-foei-config.xml similarity index 100% rename from tests/com/META-INF/foei-config.xml rename to tests/META-INF/test-foei-config.xml diff --git a/tests/com/META-INF/foei.properties b/tests/META-INF/test-foei.properties similarity index 92% rename from tests/com/META-INF/foei.properties rename to tests/META-INF/test-foei.properties index 4bcc195..127520f 100644 --- a/tests/com/META-INF/foei.properties +++ b/tests/META-INF/test-foei.properties @@ -1,7 +1,7 @@ foei.context_name=TEST-0 -foei.event_thread_listeners=tests.TestEventThreadListener +foei.event_thread_listeners=com.idcanet.foei.TestEventThreadListener foei.event_executor_manager.pool_core_size=5 foei.event_executor_manager.pool_max_size=10 diff --git a/tests/com/idcanet/foei/SimpleFoeiTests.java b/tests/com/idcanet/foei/SimpleFoeiTests.java index c2364f5..d34eed8 100644 --- a/tests/com/idcanet/foei/SimpleFoeiTests.java +++ b/tests/com/idcanet/foei/SimpleFoeiTests.java @@ -1,8 +1,47 @@ - +/* + * 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; +import java.io.InputStream; +import java.util.Date; +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; +import com.idcanet.foei.event.EventPort; +import com.idcanet.foei.event.IllegalEventPortNameException; +import com.idcanet.foei.server.FoeiContextManager; +import com.idcanet.foei.server.FoeiContextManagerFactory; + +import junit.framework.TestCase; /** * @@ -10,5 +49,119 @@ package com.idcanet.foei; * @author Willem Cazander * @version 1.0 Jul 27, 2006 */ -public class SimpleFoeiTests { +public class SimpleFoeiTests extends TestCase { + + private static FoeiContext test0 = null; + + private void start() throws Exception { + if (test0!=null) { + return; + } + + // Creates FoeiContextManager + FoeiContextManager foeiContextManager = new FoeiContextManager(); + FoeiContextManagerFactory.setFoeiContextManager(foeiContextManager); + + InputStream foeiProperties = this.getClass().getResourceAsStream("/META-INF/test-foei.properties"); + Properties properties = new Properties(); + properties.load(foeiProperties); + foeiProperties.close(); + properties.put(FoeiConfigurator.ROOT_PATH,"/tmp"); + foeiContextManager.createFoeiContext(properties); + + test0 = foeiContextManager.getFoeiContext("TEST-0"); + } + + public void testStartup() throws Exception { + start(); + assertNotNull(test0); + } + + public void testFoeiProcessLife() throws Exception { + start(); + FoeiProcess proc = test0.getFoeiProcessManager().createFoeiProcess("testProces",test0); + assertNotNull(proc); + test0.getFoeiProcessManager().destroyFoeiProcess("testProces"); + assertNull(test0.getFoeiProcessManager().getFoeiProcess("testProces")); + } + + + + public void testSimpleSpeed() throws Exception { + start(); + FoeiProcess proc = test0.getFoeiProcessManager().createFoeiProcess("testSpeed0",test0); + assertNotNull(proc); + + DummyOutputPort in = new DummyOutputPort(); + Filter f1 = new Filter(); + Filter f2 = new Filter(); + Filter f3 = new Filter(); + SpeedTestPort out = new SpeedTestPort(); + + //in.getOutputPort(EventPort.OUTPUT).setImmediate(true); + + // saves 300ms on 100k records + f1.getOutputPort(EventPort.PASS).setImmediate(true); + f2.getOutputPort(EventPort.PASS).setImmediate(true); + f3.getOutputPort(EventPort.PASS).setImmediate(true); + + // has no effect !! + //out.getInputPort(EventPort.INPUT).setImmediate(true); + + proc.addBinding(in.getOutputPort(EventPort.OUTPUT), f1.getInputPort(EventPort.INPUT)); + proc.addBinding(f1.getOutputPort(EventPort.PASS), f2.getInputPort(EventPort.INPUT)); + proc.addBinding(f2.getOutputPort(EventPort.PASS), f3.getInputPort(EventPort.INPUT)); + proc.addBinding(f3.getOutputPort(EventPort.PASS), out.getInputPort(EventPort.INPUT)); + + long startTime = System.currentTimeMillis(); + for (int i=0;i<100000;i++) { + SpeedModel m = new SpeedModel(); + + // IN FOEI it is; + //proc.executeEvent(in.getOutputPort(EventPort.OUTPUT), m); + + // running outside foei context thread use; + proc.getFoeiContext().getEventExecutorManager().executeEvent(in.getOutputPort(EventPort.OUTPUT), m, proc); + } + proc.getFoeiContext().getEventExecutorManager().executeEvent(in.getOutputPort(EventPort.OUTPUT), new Date(), proc); + long endTime = System.currentTimeMillis(); + System.out.println("Done sending in: "+(endTime-startTime)+" ms."); + Thread.sleep(50000); // todo: create destory context on end of event que + System.out.println("End speedtest"); + test0.getFoeiProcessManager().destroyFoeiProcess("testSpeed0"); + } + +} +class SpeedModel { + Date dateCreated = new Date(); + Date dateDone = null; +} +class SpeedTestPort extends AbstractEventInput { + + /** v1.0 */ + static final long serialVersionUID = 10l; + Date startTime = new Date(); + + + /** + * Creates the output port + */ + public SpeedTestPort() { + addInputPort(EventPort.INPUT,Object.class); + } + + /** + * @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 { + if (object instanceof SpeedModel) { + SpeedModel m = (SpeedModel)object; + m.dateDone=new Date(); + return; + } + // other object == end of test + long endTime = System.currentTimeMillis(); + System.out.println("End of test: "+(endTime-startTime.getTime())+" ms."); + } } \ No newline at end of file diff --git a/tests/com/idcanet/foei/TestEventThreadListener.java b/tests/com/idcanet/foei/TestEventThreadListener.java index 4b89e2b..da12890 100644 --- a/tests/com/idcanet/foei/TestEventThreadListener.java +++ b/tests/com/idcanet/foei/TestEventThreadListener.java @@ -1,3 +1,28 @@ +/* + * 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;