[svn r325] some cleaning, adding speed improvements !!, and started on junit tests.
This commit is contained in:
parent
21f99c5634
commit
7c57017fff
|
@ -9,5 +9,6 @@
|
||||||
<classpathentry kind="lib" path="lib/juel-2.1.0-rc1-impl.jar"/>
|
<classpathentry kind="lib" path="lib/juel-2.1.0-rc1-impl.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/jms-api.jar"/>
|
<classpathentry kind="lib" path="lib/jms-api.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/servlet-api.jar"/>
|
<classpathentry kind="lib" path="lib/servlet-api.jar"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,6 @@ import com.idcanet.foei.event.EventPort;
|
||||||
import com.idcanet.foei.event.EventPortType;
|
import com.idcanet.foei.event.EventPortType;
|
||||||
import com.idcanet.foei.event.EventStep;
|
import com.idcanet.foei.event.EventStep;
|
||||||
import com.idcanet.foei.event.IllegalEventPortNameException;
|
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
|
* Fiters the object on the Input port throw all
|
||||||
|
@ -86,7 +84,8 @@ public class Filter extends AbstractEventObjectStepController
|
||||||
@Override
|
@Override
|
||||||
public Object processEventSteps(Object object) {
|
public Object processEventSteps(Object object) {
|
||||||
Object o = object;
|
Object o = object;
|
||||||
for(EventStep e:getEventSteps()) {
|
for (int i=0;i<getEventSteps().size();i++) {
|
||||||
|
EventStep e = getEventSteps().get(i); // faster then useing iterator object in j5 for loop
|
||||||
if(o==null) {
|
if(o==null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class GetBeanProperty extends AbstractEventObject
|
||||||
|
|
||||||
private String property = null;
|
private String property = null;
|
||||||
|
|
||||||
private Object propertyValue = null;
|
//private Object propertyValue = null;
|
||||||
/**
|
/**
|
||||||
* Creates an SetBeanProperty
|
* Creates an SetBeanProperty
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class ObjectChangedBuffer extends AbstractEventObject {
|
||||||
/** The logger to log to. */
|
/** The logger to log to. */
|
||||||
private Logger logger = null;
|
private Logger logger = null;
|
||||||
/** The last object */
|
/** The last object */
|
||||||
private Map<Class,Object> bufferedObjects = null;
|
private Map<Class<?>,Object> bufferedObjects = null;
|
||||||
|
|
||||||
public static final String NO_CHANGE = "noChange";
|
public static final String NO_CHANGE = "noChange";
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public class ObjectChangedBuffer extends AbstractEventObject {
|
||||||
addInputPort(EventPort.INPUT);
|
addInputPort(EventPort.INPUT);
|
||||||
addOutputPort(EventPort.OUTPUT);
|
addOutputPort(EventPort.OUTPUT);
|
||||||
addOutputPort(NO_CHANGE);
|
addOutputPort(NO_CHANGE);
|
||||||
bufferedObjects = Collections.synchronizedMap(new HashMap<Class,Object>(2));
|
bufferedObjects = Collections.synchronizedMap(new HashMap<Class<?>,Object>(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -75,7 +75,7 @@ public interface FoeiConfigurator {
|
||||||
static public final String X2O_ROOT_TAG = "foei.x2o_root_tag";
|
static public final String X2O_ROOT_TAG = "foei.x2o_root_tag";
|
||||||
|
|
||||||
/** The default FoeiConfigurator */
|
/** The default FoeiConfigurator */
|
||||||
static public final Class DEFAULT_FOEI_CONFIGURATOR = FoeiConfiguratorImpl.class;
|
static public final Class<?> DEFAULT_FOEI_CONFIGURATOR = FoeiConfiguratorImpl.class;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an FoeiContext
|
* Starts an FoeiContext
|
||||||
|
|
|
@ -59,6 +59,13 @@ public interface ObjectBindingsManager
|
||||||
*/
|
*/
|
||||||
public List<EventPort> getBindings(EventPort eventPort);
|
public List<EventPort> 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<EventPort> getBindingsInputPorts(EventPort eventPort);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the bindings in an xml format to render with dotty.
|
* Returns the bindings in an xml format to render with dotty.
|
||||||
|
|
|
@ -106,15 +106,19 @@ public class EventExecutorImpl implements EventExecutor {
|
||||||
}
|
}
|
||||||
if(eventPort.getEventPortType()==EventPortType.output) {
|
if(eventPort.getEventPortType()==EventPortType.output) {
|
||||||
eventPort.addEventsPassed(); // inc output port
|
eventPort.addEventsPassed(); // inc output port
|
||||||
List<EventPort> bindings = foeiProcess.getBindings(eventPort);
|
|
||||||
for(EventPort port:bindings) {
|
// uses the faster routine to get bindings ...,
|
||||||
|
//List<EventPort> bindings = foeiProcess.getBindings(eventPort);
|
||||||
|
List<EventPort> bindings = foeiProcess.getBindingsInputPorts(eventPort);
|
||||||
|
|
||||||
|
for (int i=0;i<bindings.size();i++) {
|
||||||
|
EventPort port = bindings.get(i); // faster then using iterator (auto)
|
||||||
|
//for(EventPort port:bindings) {
|
||||||
EventInput eventInput = (EventInput)port.getEventObject();
|
EventInput eventInput = (EventInput)port.getEventObject();
|
||||||
if(port.isImmediate()) {
|
if(port.isImmediate()) {
|
||||||
logger.finer("Executing event of: "+port.getEventObject()+" port:"+port.getName()+" object: "+eventObject);
|
|
||||||
port.addEventsPassed(); // inc Immediate import port
|
port.addEventsPassed(); // inc Immediate import port
|
||||||
eventInput.doEvent(port,eventObject);
|
eventInput.doEvent(port,eventObject);
|
||||||
} else {
|
} else {
|
||||||
logger.finest("Adding event to event queue");
|
|
||||||
foeiProcess.executeEvent(port,eventObject);
|
foeiProcess.executeEvent(port,eventObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class EventExecutorManagerImpl implements EventExecutorManager {
|
||||||
/** The EventThreadListeners */
|
/** The EventThreadListeners */
|
||||||
private List<EventThreadListener> eventThreadListeners = null;
|
private List<EventThreadListener> eventThreadListeners = null;
|
||||||
/** The class for the EventExecutor */
|
/** The class for the EventExecutor */
|
||||||
private Class eventExecutorClass = null;
|
private Class<?> eventExecutorClass = null;
|
||||||
/**
|
/**
|
||||||
* Creates an EventExecutorManagerImpl ans inits the logger.
|
* Creates an EventExecutorManagerImpl ans inits the logger.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -224,7 +224,7 @@ public class FoeiConfiguratorImpl implements FoeiConfigurator {
|
||||||
* @return
|
* @return
|
||||||
* @throws ClassNotFoundException
|
* @throws ClassNotFoundException
|
||||||
*/
|
*/
|
||||||
static public Class newEventExecutorClass(Map<String,String> properties) throws ClassNotFoundException {
|
static public Class<?> newEventExecutorClass(Map<String,String> properties) throws ClassNotFoundException {
|
||||||
String className = properties.get(FoeiConfigurator.EVENT_EXECUTOR);
|
String className = properties.get(FoeiConfigurator.EVENT_EXECUTOR);
|
||||||
if(className==null) {
|
if(className==null) {
|
||||||
return EventExecutorImpl.class;
|
return EventExecutorImpl.class;
|
||||||
|
|
|
@ -171,6 +171,13 @@ public class FoeiProcessImpl implements FoeiProcess {
|
||||||
return getObjectBindingsManager().getBindings(eventPort);
|
return getObjectBindingsManager().getBindings(eventPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see com.idcanet.foei.core.ObjectBindingsManager#getBindingsInputPorts(com.idcanet.foei.event.EventPort)
|
||||||
|
*/
|
||||||
|
public List<EventPort> getBindingsInputPorts(EventPort eventPort) {
|
||||||
|
return getObjectBindingsManager().getBindingsInputPorts(eventPort);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see com.idcanet.foei.core.ObjectBindingsManager#getBindingsAsXML()
|
* @see com.idcanet.foei.core.ObjectBindingsManager#getBindingsAsXML()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -147,7 +147,7 @@ public class ObjectBindingsManagerImpl implements ObjectBindingsManager {
|
||||||
if(eventPort==null) {
|
if(eventPort==null) {
|
||||||
throw new NullPointerException("eventPort may not be null.");
|
throw new NullPointerException("eventPort may not be null.");
|
||||||
}
|
}
|
||||||
List<EventPort> result = new ArrayList<EventPort>(0);
|
List<EventPort> result = new ArrayList<EventPort>(6);
|
||||||
List<EventPort> inputPorts = bindingsInput.get(eventPort);
|
List<EventPort> inputPorts = bindingsInput.get(eventPort);
|
||||||
List<EventPort> outputPorts = bindingsOutput.get(eventPort);
|
List<EventPort> outputPorts = bindingsOutput.get(eventPort);
|
||||||
if(inputPorts!=null) {
|
if(inputPorts!=null) {
|
||||||
|
@ -159,6 +159,26 @@ public class ObjectBindingsManagerImpl implements ObjectBindingsManager {
|
||||||
return result;
|
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<EventPort> 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<EventPort> inputPorts = bindingsOutput.get(eventPort);
|
||||||
|
if(inputPorts!=null) {
|
||||||
|
return inputPorts;
|
||||||
|
}
|
||||||
|
List<EventPort> result = new ArrayList<EventPort>(0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the dotty xml bindings
|
* Returns the dotty xml bindings
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -36,8 +36,6 @@ import com.idcanet.foei.event.EventPort;
|
||||||
import com.idcanet.x4o.element.AbstractElement;
|
import com.idcanet.x4o.element.AbstractElement;
|
||||||
import com.idcanet.x4o.element.ElementException;
|
import com.idcanet.x4o.element.ElementException;
|
||||||
|
|
||||||
import org.xml.sax.Attributes;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|
|
@ -64,7 +64,7 @@ abstract public class AbstractEventInput implements EventInput {
|
||||||
* @param inputName The inputName of the EventPort
|
* @param inputName The inputName of the EventPort
|
||||||
* @param inputType The inputClass 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) {
|
if(inputName==null) {
|
||||||
throw new NullPointerException("inputName may not be null.");
|
throw new NullPointerException("inputName may not be null.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,8 @@ import java.util.Map;
|
||||||
* @author Willem Cazander
|
* @author Willem Cazander
|
||||||
* @version 1.0 Aug 17, 2005
|
* @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 */
|
/** The input EventPorts */
|
||||||
private Map<String,EventPort> inputs = null;
|
private Map<String,EventPort> inputs = null;
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ abstract public class AbstractEventObject extends AbstractEventOutput implements
|
||||||
* @param inputName The inputName of the EventPort
|
* @param inputName The inputName of the EventPort
|
||||||
* @param inputType The inputType 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) {
|
if(inputName==null) {
|
||||||
throw new NullPointerException("inputName may not be null.");
|
throw new NullPointerException("inputName may not be null.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ abstract public class AbstractEventOutput implements EventOutput {
|
||||||
* @param outputName The outputName of the EventPort.
|
* @param outputName The outputName of the EventPort.
|
||||||
* @param outputType The output Class type 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) {
|
if(outputName==null) {
|
||||||
throw new NullPointerException("outputName may not be null.");
|
throw new NullPointerException("outputName may not be null.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,17 +37,23 @@ package com.idcanet.foei.event;
|
||||||
*/
|
*/
|
||||||
public class EventPort {
|
public class EventPort {
|
||||||
|
|
||||||
|
/** public type for defining TRUE */
|
||||||
static final public String TRUE = "true";
|
static final public String TRUE = "true";
|
||||||
|
/** public type for defining FALSE */
|
||||||
static final public String FALSE = "false";
|
static final public String FALSE = "false";
|
||||||
|
/** public type for defining INPUT */
|
||||||
static final public String INPUT = "input";
|
static final public String INPUT = "input";
|
||||||
|
/** public type for defining OUTPUT */
|
||||||
static final public String OUTPUT = "output";
|
static final public String OUTPUT = "output";
|
||||||
|
/** public type for defining PASS */
|
||||||
static final public String PASS = "pass";
|
static final public String PASS = "pass";
|
||||||
|
/** public type for defining DROP */
|
||||||
static final public String DROP = "drop";
|
static final public String DROP = "drop";
|
||||||
|
|
||||||
/** The name of the port */
|
/** The name of the port */
|
||||||
private String name = null;
|
private String name = null;
|
||||||
/** The type of Object class which can be handled by the port.*/
|
/** 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. */
|
/** The total number of events this port has had. */
|
||||||
private long eventsPassed = 0;
|
private long eventsPassed = 0;
|
||||||
/** The type of event port */
|
/** The type of event port */
|
||||||
|
@ -68,7 +74,7 @@ public class EventPort {
|
||||||
* @param name The name of the EventPort.
|
* @param name The name of the EventPort.
|
||||||
* @param objectType The class type which it accepts.
|
* @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) {
|
if(name==null) {
|
||||||
throw new NullPointerException("name may not be 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.
|
* Returns the class of the object this EventPort handleds.
|
||||||
* @return the class of the transfering object.
|
* @return the class of the transfering object.
|
||||||
*/
|
*/
|
||||||
public Class getObjectClass() {
|
public Class<?> getObjectClass() {
|
||||||
return objectType;
|
return objectType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,13 @@ package com.idcanet.foei.event;
|
||||||
*/
|
*/
|
||||||
public enum EventPortType {
|
public enum EventPortType {
|
||||||
|
|
||||||
input,
|
/**
|
||||||
output;
|
* Type for input ports
|
||||||
|
*/
|
||||||
|
input,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type for output ports
|
||||||
|
*/
|
||||||
|
output;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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();
|
|
||||||
}
|
|
|
@ -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<String,ConnectionProvider> 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<String,ConnectionProvider>(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<ConnectionProvider> getConnectionProviders() {
|
|
||||||
return connectionProviders.values();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,61 +0,0 @@
|
||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<!--
|
|
||||||
|
|
||||||
@(#)package.html 1.00
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
-->
|
|
||||||
</head>
|
|
||||||
<body bgcolor="white">
|
|
||||||
An generic ConnectionProvider with default jndi support.<br/>
|
|
||||||
|
|
||||||
<h2>Package Specification</h2>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<li>Full J2SE 5 compatible</li>
|
|
||||||
<li>Small package</li>
|
|
||||||
</ul>
|
|
||||||
<!--
|
|
||||||
<ul>
|
|
||||||
<li><a href="">hgj</a>
|
|
||||||
</ul>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<h2>Related Documentation</h2>
|
|
||||||
|
|
||||||
None.
|
|
||||||
<!--
|
|
||||||
For overviews, tutorials, examples, guides, and tool documentation, please see:
|
|
||||||
<ul>
|
|
||||||
<li><a href="http://foei.idca.nl/docs/jmx/example1">Example 1</a>
|
|
||||||
</ul>
|
|
||||||
-->
|
|
||||||
<!-- Put @see and @since tags down here. -->
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -38,8 +38,8 @@ import java.io.PrintStream;
|
||||||
* @author Willem Cazander
|
* @author Willem Cazander
|
||||||
* @version 1.0 Jan 18, 2006
|
* @version 1.0 Jan 18, 2006
|
||||||
*/
|
*/
|
||||||
public class ContextListWriter
|
public class ContextListWriter {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* writes an context tree to the printstream out.
|
* writes an context tree to the printstream out.
|
||||||
* @param out The printstream to which the text line are printed.
|
* @param out The printstream to which the text line are printed.
|
||||||
|
@ -52,7 +52,7 @@ public class ContextListWriter
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
NamingEnumeration list = ctx.listBindings("");
|
NamingEnumeration<Binding> list = ctx.listBindings("");
|
||||||
while (list.hasMore()) {
|
while (list.hasMore()) {
|
||||||
Binding item = (Binding)list.next();
|
Binding item = (Binding)list.next();
|
||||||
String className = item.getClassName();
|
String className = item.getClassName();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
foei.context_name=TEST-0
|
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_core_size=5
|
||||||
foei.event_executor_manager.pool_max_size=10
|
foei.event_executor_manager.pool_max_size=10
|
|
@ -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;
|
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
|
* @author Willem Cazander
|
||||||
* @version 1.0 Jul 27, 2006
|
* @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.");
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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;
|
package com.idcanet.foei;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue