CooWS/ 0000755 0001750 0001750 00000000000 10260270013 012643 5 ustar joshua joshua 0000000 0000000 CooWS/lib/ 0000755 0001750 0001750 00000000000 10240174701 013416 5 ustar joshua joshua 0000000 0000000 CooWS/lib/ext/ 0000755 0001750 0001750 00000000000 10232211735 014216 5 ustar joshua joshua 0000000 0000000 CooWS/lib/ext/tomcat-clib 0000777 0001750 0001750 00000000000 10232211735 023702 2../../../../apps/tomcat/common/lib/ ustar joshua joshua 0000000 0000000 CooWS/lib/ext/tomcat-slib 0000777 0001750 0001750 00000000000 10232211720 023672 2../../../../apps/tomcat/shared/lib/ ustar joshua joshua 0000000 0000000 CooWS/src/ 0000755 0001750 0001750 00000000000 10260252000 013426 5 ustar joshua joshua 0000000 0000000 CooWS/src/org/ 0000755 0001750 0001750 00000000000 10222010276 014222 5 ustar joshua joshua 0000000 0000000 CooWS/src/org/coows/ 0000755 0001750 0001750 00000000000 10257031230 015355 5 ustar joshua joshua 0000000 0000000 CooWS/src/org/coows/ws/ 0000755 0001750 0001750 00000000000 10222011241 015776 5 ustar joshua joshua 0000000 0000000 CooWS/src/org/coows/ws/CooWS.java 0000664 0001750 0001750 00000002106 10264751356 017664 0 ustar joshua joshua 0000000 0000000 package org.coows.ws;
import org.coows.CooEventAchieve;
import org.coows.CooEventPlanOutcome;
import org.coows.CooEventRemote;
import org.coows.ICooBpelProcess;
import org.coows.ICooEvent;
import org.coows.engine.CooEngine;
import org.coows.engine.CooException;
/**
* The CooWS Web Service
*/
public class CooWS {
public void dispatchEventRemote(CooEventRemote aREvent) {
CooEngine.getMAgentsManager().dispatchEvent(aREvent);
}
private void dispatchEvent(ICooEvent anEvent) {
CooEngine.getMAgentsManager().dispatchEvent(anEvent);
}
public void achieve(String anAgent, String anIntentionID, String aDes) {
dispatchEvent(new CooEventAchieve(anAgent, anIntentionID, aDes));
}
public void planOutcome(String anAgent,
String intentionID, boolean outcome) {
dispatchEvent(new CooEventPlanOutcome(anAgent, intentionID, outcome));
}
public ICooBpelProcess getBPELProcess(String aServiceName)
throws CooException {
return CooEngine.getMProcessesManager().getProcess(aServiceName);
}
}
CooWS/src/org/coows/ws/WSProvider.java 0000644 0001750 0001750 00000000361 10237672255 020735 0 ustar joshua joshua 0000000 0000000 package org.coows.ws;
/**
*
*/
public class WSProvider
{
public int getPrice(String itemID)
{
return 42;
}
public boolean checkAvailability(String creditCardNumber, int amount)
{
return true;
}
}
CooWS/src/org/coows/ws/package.html 0000644 0001750 0001750 00000000114 10204377422 020273 0 ustar joshua joshua 0000000 0000000
CooWS web services classes
CooWS/src/org/coows/aux/ 0000755 0001750 0001750 00000000000 10222011241 016142 5 ustar joshua joshua 0000000 0000000 CooWS/src/org/coows/aux/InvokePlan.java 0000644 0001750 0001750 00000002132 10236630113 021063 0 ustar joshua joshua 0000000 0000000 package org.coows.aux;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.encoding.XMLType;
/**
*
*/
public class InvokePlan {
public static void main(String[] args) {
Call call;
try {
call = createInvokeCall();
System.out.println("[CooBpelProcessBPR.invoke] "
+ "call created! now invoking!");
call.invoke(new Object[] { "agenteDiProva" });
} catch (Exception e) {
System.out.println("Error invoking bpel process "
+ e.getLocalizedMessage());
}
}
public static Call createInvokeCall() throws ServiceException,
MalformedURLException {
Call call = (Call) new Service().createCall();
call.setTargetEndpointAddress(new URL(
"http://localhost:4444/active-bpel/services/runPlanService"));
call.setOperationName("runPlanOp");
// Adding parameters to call
call.addParameter("agentID", XMLType.XSD_STRING, ParameterMode.IN);
call.setOperationStyle("rpc");
return call;
}
}
CooWS/src/org/coows/aux/PopulateDB.java 0000644 0001750 0001750 00000007277 10236630002 021030 0 ustar joshua joshua 0000000 0000000 package org.coows.aux;
import org.coows.CooAccessSpecifierPrivate;
import org.coows.CooAccessSpecifierPublic;
import org.coows.CooAgent;
import org.coows.CooBpelProcessBpr;
import org.coows.CooDesire;
import org.coows.CooPlan;
import org.coows.engine.CooEngine;
import org.coows.engine.CooEngineConfiguration;
import org.coows.engine.CooException;
import org.coows.engine.CooPersistenceManager;
import org.coows.util.CooAgentState;
import org.coows.util.CooBprFile;
import org.coows.util.CooSetOfPlans;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Vector;
/**
*
*/
public class PopulateDB {
public void populateProcessesTable(CooEngineConfiguration aConf)
throws CooException {
CooBpelProcessBpr currProcess;
Vector setOfProcesses = new Vector();
try {
currProcess = createProcess("runPlanService",
System.getProperties().getProperty("user.home")
+ "/temp/plan1Body.bpr");
setOfProcesses.add(currProcess);
CooPersistenceManager.serializeProcesses(aConf, setOfProcesses);
System.out.println("[PopulateDB] processes added to db!");
} catch (Exception e) {
throw new CooException(
"[PopulateDB] Error while populatin processes DB!\n"
+ e.getMessage());
}
}
/**
* @return
*
* @throws IOException
*/
private CooBpelProcessBpr createProcess(
String aServiceName,
String aBprFilePath)
throws IOException {
CooBpelProcessBpr res = new CooBpelProcessBpr();
BufferedInputStream buf;
buf = new BufferedInputStream(new FileInputStream(aBprFilePath));
byte[] bytes = new byte[buf.available()];
buf.read(bytes, 0, buf.available());
ByteArrayInputStream bytearray = new ByteArrayInputStream(bytes);
CooBprFile bpr = new CooBprFile(bytearray);
res.setServiceName(aServiceName);
res.setBprFile(bpr);
return res;
}
private void populateAgentsTable(CooEngineConfiguration aConf)
throws CooException {
Collection aSetOfAgents = createSetOfAgentsState();
CooPersistenceManager.serializeAgents(aConf, aSetOfAgents);
}
private Collection createSetOfAgentsState() throws CooException {
Vector res = new Vector();
CooAgent agent;
CooAgentState agentState;
CooSetOfPlans sop;
CooPlan plan;
for (int i = 0; i < 2; i++) {
sop = new CooSetOfPlans();
plan = new CooPlan("plan" + (3 * i), new CooDesire("trigger"
+ (3 * i)), "runPlanService", CooAccessSpecifierPublic
.getInstance());
sop.addPlan(plan);
plan = new CooPlan("plan" + ((3 * i) + 1), new CooDesire("trigger"
+ ((3 * i) + 1)), "runPlanService",
CooAccessSpecifierPrivate.getInstance());
sop.addPlan(plan);
plan = new CooPlan("plan" + ((3 * i) + 2), new CooDesire("trigger"
+ ((3 * i) + 2)), "runPlanService",
CooAccessSpecifierPublic.getInstance());
sop.addPlan(plan);
agentState = new CooAgentState("agent" + i, sop, new Vector(),
CooAgent.RETRIEVAL_STRATEGY_NOLOCAL,
CooAgent.ACQUISITION_STRATEGY_ADD);
agent = new CooAgent(agentState);
res.add(agent);
}
return res;
}
public static void main(String[] args) throws CooException {
PopulateDB pd = new PopulateDB();
CooEngine.initTEMP("cooEngineConf.xml", System.getProperties()
.getProperty("user.home")
+ "/temp");
pd.populateProcessesTable(CooEngine.getMConfig());
Hashtable setOfProcesses = CooPersistenceManager
.restoreBpelProcesses(CooEngine.getMConfig());
pd.populateAgentsTable(CooEngine.getMConfig());
// TEST: Hashtable setOfAgents =
// CooPersistenceManager.restoreAgents(aConf);
}
}
CooWS/src/org/coows/ser/ 0000755 0001750 0001750 00000000000 10222011241 016136 5 ustar joshua joshua 0000000 0000000 CooWS/src/org/coows/ser/CooBprFileDeserializer.java 0000664 0001750 0001750 00000001533 10261253243 023351 0 ustar joshua joshua 0000000 0000000 package org.coows.ser;
import javax.xml.namespace.QName;
import org.apache.axis.encoding.ser.SimpleDeserializer;
import org.coows.engine.CooException;
import org.coows.util.CooBprFile;
/**
*
*/
public class CooBprFileDeserializer
extends SimpleDeserializer
{
/**
* The Deserializer is constructed with the xmlType and javaType
*/
public CooBprFileDeserializer(Class javaType, QName xmlType)
{
super(javaType, xmlType);
}
/**
* @see org.apache.axis.encoding.ser.
* SimpleDeserializer#makeValue(java.lang.String)
*/
public Object makeValue(String source)
{
try
{
return new CooBprFile(source);
}
catch (Exception e)
{
CooException.logError(e, "Error deserializing bpr file.");
return new CooBprFile("");
}
}
}
CooWS/src/org/coows/ser/CooBrpFileSerializerFactory.java 0000664 0001750 0001750 00000000730 10160572650 024372 0 ustar joshua joshua 0000000 0000000 package org.coows.ser;
import javax.xml.namespace.QName;
import org.apache.axis.encoding.ser.BaseSerializerFactory;
/**
* A custom Axis date serializer factory.
*/
public class CooBrpFileSerializerFactory extends BaseSerializerFactory
{
/**
* Creates a serializer factory with the given java type and xml type.
*/
public CooBrpFileSerializerFactory(Class javaType, QName xmlType)
{
super(CooBprFileSerializer.class, xmlType, javaType);
}
}
CooWS/src/org/coows/ser/CooBprFileSerializer.java 0000664 0001750 0001750 00000001213 10227225132 023031 0 ustar joshua joshua 0000000 0000000 package org.coows.ser;
import javax.xml.namespace.QName;
import org.apache.axis.encoding.SerializationContext;
import org.apache.axis.encoding.ser.SimpleSerializer;
import org.coows.util.CooBprFile;
/**
*
*/
public class CooBprFileSerializer extends SimpleSerializer
{
/**
* The Serializer is constructed with the xmlType and javaType
*/
public CooBprFileSerializer(Class javaType, QName xmlType)
{
super(javaType, xmlType);
}
public String getValueAsString(Object aValue, SerializationContext aContext)
{
CooBprFile bprFile = (CooBprFile) aValue;
return bprFile.toString();
}
}
CooWS/src/org/coows/ser/package.html 0000644 0001750 0001750 00000000127 10204377334 020441 0 ustar joshua joshua 0000000 0000000
CooWS serializer/deserializer classes
CooWS/src/org/coows/ser/CooBprFileDeserializerFactory.java 0000664 0001750 0001750 00000000746 10160572703 024711 0 ustar joshua joshua 0000000 0000000 package org.coows.ser;
import javax.xml.namespace.QName;
import org.apache.axis.encoding.ser.BaseDeserializerFactory;
/**
* A custom Axis date deserializer factory.
*/
public class CooBprFileDeserializerFactory extends BaseDeserializerFactory
{
/**
* Creates a deserializer factory with the given java type and xml type.
*/
public CooBprFileDeserializerFactory(Class javaType, QName xmlType)
{
super(CooBprFileDeserializer.class, xmlType, javaType);
}
}
CooWS/src/org/coows/web/ 0000755 0001750 0001750 00000000000 10222011241 016122 5 ustar joshua joshua 0000000 0000000 CooWS/src/org/coows/web/CooEngineServlet.java 0000644 0001750 0001750 00000002763 10261253423 022225 0 ustar joshua joshua 0000000 0000000 package org.coows.web;
import org.apache.axis.transport.http.AxisServlet;
import org.coows.engine.CooEngine;
import org.coows.engine.CooException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
/**
* The CooWS servlet
*/
public class CooEngineServlet
extends AxisServlet
{
public void destroy()
{
try {
CooEngine.shutdown();
}
catch (CooException e) {
System.err.println("CooWS ERROR while shutdown!!!!");
e.printStackTrace();
}
super.destroy();
}
public void init(ServletConfig aConfig)
throws ServletException
{
try
{
startEngine();
super.init(aConfig);
}
catch (Exception e)
{
throw new ServletException(e);
}
}
private void startEngine()
{
Runnable starter = new Runnable()
{
public void run()
{
try
{
try
{
Thread.sleep(5000);
}
catch (InterruptedException e) {}
CooEngine.init();
}
catch (Throwable ie)
{
System.err.println("ERROR! UNABLE TO START COOWS ENGINE!");
}
}
};
Thread startThread = new Thread(starter);
startThread.start();
}
}
CooWS/src/org/coows/test/ 0000755 0001750 0001750 00000000000 10247315316 016345 5 ustar joshua joshua 0000000 0000000 CooWS/src/org/coows/test/BpelProcessesFactory.java 0000664 0001750 0001750 00000001543 10204376763 023324 0 ustar joshua joshua 0000000 0000000 package org.coows.test;
import org.coows.CooBpelProcessBpr;
import org.coows.util.CooBprFile;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
public class BpelProcessesFactory
{
public static CooBpelProcessBpr createProcess(String aProcessName)
{
String aBprFilePath = "/home/joshua/workspace/";
CooBprFile bprFile;
CooBpelProcessBpr res;
try
{
BufferedInputStream buf = new BufferedInputStream(new FileInputStream(aBprFilePath));
byte[] bytes = new byte[buf.available()];
buf.read(bytes, 0, buf.available());
bprFile = new CooBprFile(new ByteArrayInputStream(bytes));
res = new CooBpelProcessBpr(bprFile, aProcessName);
return res;
}
catch(Exception e)
{
System.err.println("Error creating bpelProcess!\n" + e.getMessage());
return null;
}
}
}
CooWS/src/org/coows/test/SandBox.java 0000644 0001750 0001750 00000000426 10204377012 020542 0 ustar joshua joshua 0000000 0000000 package org.coows.test;
import com.thoughtworks.xstream.XStream;
/**
*
*/
public class SandBox
{
public void testXStream()
{
XStream xstream = new XStream();
}
public static void main(String[] args)
{
SandBox test = new SandBox();
test.testXStream();
}
}
CooWS/src/org/coows/test/WSRunPlanTestClient.java 0000644 0001750 0001750 00000003465 10205405321 023036 0 ustar joshua joshua 0000000 0000000 package org.coows.test;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.rpc.ParameterMode;
/**
*
*/
public class WSRunPlanTestClient
{
public static void main(String[] args)
{
try
{
WSRunPlanTestClient client = new WSRunPlanTestClient();
String result = client.run("Ciao!");
System.out.println("Received: " + result);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public WSRunPlanTestClient() throws Exception
{ }
/**
* Creates a SOAP RPC call, calls the BPEL process Web service, and returns
* the result returned from the server. If an AxisFault is caught and it
* contains the magic fault string, we return that string instead of
* re-throwing the fault.
*
*/
public String run(String arg)
throws Exception
{
// Call BPEL process Web service using RPC
Call call = createCall();
String result = null;
try
{
result = (String)call.invoke( new Object[] { arg } );
}
catch (Exception e)
{
result = "unexpected exception seen: " + e.toString();
}
return result;
}
/**
* Creates and returns an RPC SOAP call. The call's parameter values are taken
* from the config file.
*
* @return an RPC SOAP call
*/
protected Call createCall()
throws Exception
{
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new java.net.URL("http://localhost:8080/active-bpel/services/runPlanService"));
call.setOperationName("runPlanOp");
call.addParameter("agentID", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);
call.setReturnType(org.apache.axis.Constants.XSD_STRING);
return call;
}
}
CooWS/src/org/coows/test/DispatchEventProvidedTestClient.java 0000644 0001750 0001750 00000011233 10247340035 025441 0 ustar joshua joshua 0000000 0000000 package org.coows.test;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Vector;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
import org.coows.CooAccessSpecifierOnlyTrusted;
import org.coows.CooAccessSpecifierPrivate;
import org.coows.CooAccessSpecifierPublic;
import org.coows.CooBpelProcessBpr;
import org.coows.CooDesire;
import org.coows.CooEventProvided;
import org.coows.CooEventRemote;
import org.coows.CooEventRequested;
import org.coows.CooPlan;
import org.coows.ICooEvent;
import org.coows.ser.CooBprFileDeserializerFactory;
import org.coows.ser.CooBrpFileSerializerFactory;
import org.coows.util.CooBprFile;
import org.coows.util.CooRequestID;
import org.coows.util.CooSetOfPlans;
public class DispatchEventProvidedTestClient {
public static void main(String[] args)
{
Vector calls = new Vector();
Vector requested = new Vector();
try
{
Call call = createCall();
CooEventProvided prov = new CooEventProvided("agent0","agent1",null,null);
CooPlan aPlan = new CooPlan("aPlanID",new CooDesire("aTrigger"), "runPlan", CooAccessSpecifierPublic.getInstance());
CooSetOfPlans aSop = new CooSetOfPlans();
aSop.addPlan(aPlan);
prov.setMProvidedPlans(aSop);
for (int i=3; i<4; i++)
{
prov.setMReqID(new CooRequestID("intentionID","instanceID"));
System.out.println("Sending event "+prov);
call.invoke(new Object[]{new CooEventRemote(prov,"localhost")});
}
}
catch(Exception ex)
{
System.out.println("Error invoking WS: " + ex.getMessage());
ex.printStackTrace();
}
} // end of main
public static Call createCall() throws ServiceException, MalformedURLException
{
Call call = (Call)new Service().createCall();
call.setTargetEndpointAddress(new URL("http://localhost:4444/active-bpel/services/CooWS"));
// Registering type mapping
call.registerTypeMapping(CooDesire.class, new QName("urn:coows", "Desire"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooPlan.class, new QName("urn:coows", "Plan"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooAccessSpecifierPublic.class, new QName("urn:coows", "AccessSpecifierPublic"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooAccessSpecifierPrivate.class, new QName("urn:coows", "AccessSpecifierPrivate"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooAccessSpecifierOnlyTrusted.class, new QName("urn:coows", "AccessSpecifierOnlyTrusted"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooBpelProcessBpr.class, new QName("urn:coows", "BpelProcessBpr"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooBprFile.class, new QName("urn:coows", "BprFile"), CooBrpFileSerializerFactory.class, CooBprFileDeserializerFactory.class);
call.registerTypeMapping(ICooEvent.class, new QName("urn:coows", "Event"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooEventRequested.class, new QName("urn:coows", "EventRequested"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooEventProvided.class, new QName("urn:coows", "EventProvided"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooEventRemote.class, new QName("urn:coows", "EventRemote"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooRequestID.class, new QName("urn:coows", "RequestID"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooSetOfPlans.class, new QName("urn:coows", "SetOfPlans"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
QName remoteEventQName = new QName("urn:coows", "EventRemote");
call.addParameter(remoteEventQName, remoteEventQName, CooEventRequested.class, ParameterMode.IN);
call.setOperationStyle("rpc");
call.setOperationName(new QName("CooWS", "dispatchEventRemote"));
return call;
}
}
CooWS/src/org/coows/test/TestCooSetOfPlans.java 0000664 0001750 0001750 00000001212 10170620375 022524 0 ustar joshua joshua 0000000 0000000 package org.coows.test;
import org.coows.CooAccessSpecifierPublic;
import org.coows.CooDesire;
import org.coows.CooPlan;
import org.coows.util.CooSetOfPlans;
import junit.framework.TestCase;
/**
*
*/
public class TestCooSetOfPlans
extends TestCase
{
public TestCooSetOfPlans(String name)
{
super(name);
}
public void testEmpty()
{
CooSetOfPlans sop = new CooSetOfPlans();
CooPlan aPlan = new CooPlan("piano", new CooDesire("desire"), null, new CooAccessSpecifierPublic());
assertTrue(sop.isEmpty());
assertEquals(0, sop.size());
sop.addPlan(aPlan);
assertTrue(!sop.isEmpty());
assertEquals(1,sop.size());
}
}
CooWS/src/org/coows/test/TestAgentQueue.java 0000644 0001750 0001750 00000002445 10243060433 022111 0 ustar joshua joshua 0000000 0000000 package org.coows.test;
import junit.framework.TestCase;
import org.coows.CooAccessSpecifierPublic;
import org.coows.CooAgent;
import org.coows.CooDesire;
import org.coows.CooEventRemote;
import org.coows.CooEventRequested;
import org.coows.CooPlan;
import org.coows.engine.CooException;
import org.coows.util.CooRequestID;
import org.coows.util.CooSetOfPlans;
public class TestAgentQueue
extends TestCase {
public TestAgentQueue(String aName)
throws CooException {
super (aName);
}
public void testARequested()
throws CooException {
CooDesire aDes = new CooDesire("aTrigger");
CooPlan aPlan = new CooPlan(
"plan0",
aDes,
"aServiceName",
CooAccessSpecifierPublic.getInstance());
CooSetOfPlans aSop = new CooSetOfPlans();
aSop.addPlan(aPlan);
CooAgent anAgent = new CooAgent(
"anAgent",
CooAgent.ACQUISITION_STRATEGY_ADD, aSop);
CooEventRequested aReq = new CooEventRequested(
"anotherAgent",
"anAgent",
new CooRequestID("anIntentionID", "anInstanceID"),
aDes);
anAgent.onEvent(aReq);
}
}
CooWS/src/org/coows/test/TestCooSetOfPlans2.java 0000664 0001750 0001750 00000001213 10200134004 022566 0 ustar joshua joshua 0000000 0000000 package org.coows.test;
import org.coows.CooAccessSpecifierPublic;
import org.coows.CooDesire;
import org.coows.CooPlan;
import org.coows.util.CooSetOfPlans;
import junit.framework.TestCase;
/**
*
*/
public class TestCooSetOfPlans2 extends TestCase
{
public TestCooSetOfPlans2(String name)
{
super(name);
}
public void testEmpty()
{
CooSetOfPlans sop = new CooSetOfPlans();
CooPlan aPlan = new CooPlan("piano", new CooDesire("desire"), null, new CooAccessSpecifierPublic());
assertTrue(sop.isEmpty());
assertEquals(0, sop.size());
sop.addPlan(aPlan);
assertTrue(!sop.isEmpty());
assertEquals(1,sop.size());
}
}
CooWS/src/org/coows/test/DispatchEventRequestedTestClient.java 0000664 0001750 0001750 00000007616 10245667030 025647 0 ustar joshua joshua 0000000 0000000 package org.coows.test;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Vector;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.ser.*;
import org.coows.CooAccessSpecifierOnlyTrusted;
import org.coows.CooAccessSpecifierPrivate;
import org.coows.CooAccessSpecifierPublic;
import org.coows.CooBpelProcessBpr;
import org.coows.CooDesire;
import org.coows.CooEventRemote;
import org.coows.ICooEvent;
import org.coows.CooEventRequested;
import org.coows.CooPlan;
import org.coows.util.CooBprFile;
import org.coows.util.CooRequestID;
import org.coows.ser.CooBprFileDeserializerFactory;
import org.coows.ser.CooBrpFileSerializerFactory;
import javax.xml.namespace.*;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
/**
*
*/
public class DispatchEventRequestedTestClient
{
public static void main(String[] args)
{
Vector calls = new Vector();
Vector requested = new Vector();
try
{
Call call = createCall();
CooEventRequested req = new CooEventRequested("agent0", "agent1", null, null);
for (int i=3; i<4; i++)
{
req.setMReqID(new CooRequestID("intentionID","instanceID"));
CooDesire des = new CooDesire("trigger"+(i%6));
System.out.println("Sending Desire: " + des);
req.setMDes(des);
call.invoke(new Object[]{new CooEventRemote(req,"localhost")});
}
}
catch(Exception ex)
{
System.out.println("Error invoking WS: " + ex.getMessage());
ex.printStackTrace();
}
} // end of main
public static Call createCall() throws ServiceException, MalformedURLException
{
Call call = (Call)new Service().createCall();
call.setTargetEndpointAddress(new URL("http://localhost:4444/active-bpel/services/CooWS"));
// Registering type mapping
call.registerTypeMapping(CooDesire.class, new QName("urn:coows", "Desire"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooPlan.class, new QName("urn:coows", "Plan"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooAccessSpecifierPublic.class, new QName("urn:coows", "AccessSpecifierPublic"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooAccessSpecifierPrivate.class, new QName("urn:coows", "AccessSpecifierPrivate"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooAccessSpecifierOnlyTrusted.class, new QName("urn:coows", "AccessSpecifierOnlyTrusted"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooBpelProcessBpr.class, new QName("urn:coows", "BpelProcessBpr"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooBprFile.class, new QName("urn:coows", "BprFile"), CooBrpFileSerializerFactory.class, CooBprFileDeserializerFactory.class);
call.registerTypeMapping(ICooEvent.class, new QName("urn:coows", "Event"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooEventRequested.class, new QName("urn:coows", "EventRequested"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooEventRemote.class, new QName("urn:coows", "EventRemote"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooRequestID.class, new QName("urn:coows", "RequestID"), BeanSerializerFactory.class, BeanDeserializerFactory.class);
QName remoteEventQName = new QName("urn:coows", "EventRemote");
call.addParameter(remoteEventQName, remoteEventQName, CooEventRequested.class, ParameterMode.IN);
call.setOperationStyle("rpc");
call.setOperationName(new QName("CooWS", "dispatchEventRemote"));
return call;
}
}
CooWS/src/org/coows/test/package.html 0000644 0001750 0001750 00000000107 10204377356 020631 0 ustar joshua joshua 0000000 0000000
CooWS testing classes
CooWS/src/org/coows/util/ 0000755 0001750 0001750 00000000000 10242125354 016337 5 ustar joshua joshua 0000000 0000000 CooWS/src/org/coows/util/CooBprFile.java 0000664 0001750 0001750 00000001032 10160575052 021167 0 ustar joshua joshua 0000000 0000000 package org.coows.util;
import java.io.ByteArrayInputStream;
/**
*
*/
public class CooBprFile
{
private ByteArrayInputStream mBprFile;
/**
* Constructor
* @param aBprFile
* @param aServiceName
*/
public CooBprFile(ByteArrayInputStream aBprFile)
{
this.mBprFile = aBprFile;
}
public CooBprFile(String aBprFileStr)
{
mBprFile = new ByteArrayInputStream(aBprFileStr.getBytes());
}
public ByteArrayInputStream getBin()
{
return mBprFile;
}
public String toString()
{
return mBprFile.toString();
}
}
CooWS/src/org/coows/util/CooSetOfIntention.java 0000644 0001750 0001750 00000002545 10254073000 022552 0 ustar joshua joshua 0000000 0000000 package org.coows.util;
import java.util.Hashtable;
import java.util.Iterator;
import org.coows.CooIntention;
import org.coows.engine.CooException;
/**
* A set of intentions
*
*/
public class CooSetOfIntention {
private Hashtable mIntentions;
public CooSetOfIntention() {
mIntentions = new Hashtable();
(new CheckSuspended()).start();
}
public void addIntention(CooIntention anIntention) {
mIntentions.put(anIntention.getMIntentionID(), anIntention);
}
public CooIntention getIntention(String anIntentionID)
throws CooException {
if (mIntentions.containsKey(anIntentionID))
return mIntentions.get(anIntentionID);
else
throw new CooException("Trying to get unknown intention!");
}
private class CheckSuspended
extends Thread {
public void run() {
Iterator i;
while(true) {
try {
sleep(10000);
} catch(Exception e) {}
for (CooIntention curr : mIntentions.values()) {
curr.checkSuspended();
if (curr.isCompleted())
mIntentions.remove(curr.getMIntentionID());
}
}
}
}
}
CooWS/src/org/coows/util/CooRequestID.java 0000644 0001750 0001750 00000002341 10257017150 021510 0 ustar joshua joshua 0000000 0000000 package org.coows.util;
/**
* Wrapper class for the "requested"/"provided" info
*
*/
public class CooRequestID {
/** The intention wich belongs the event*/
private String mIntentionID;
private String mInstanceID;
/**
* Constructor
*
*/
public CooRequestID() {
}
/**
* Constructor
* @param anIntID
* @param aPos
* @param anInstID
*/
public CooRequestID(String anIntID, String anInstID) {
mIntentionID = anIntID;
mInstanceID = anInstID;
}
public String toString() {
return "CooRequestID("+mIntentionID+","+mInstanceID+")";
}
/**
*
* @uml.property name="mInstanceID"
*/
public String getMInstanceID() {
return mInstanceID;
}
/**
*
* @uml.property name="mInstanceID"
*/
public void setMInstanceID(String instanceID) {
mInstanceID = instanceID;
}
/**
*
* @uml.property name="mIntentionID"
*/
public String getMIntentionID() {
return mIntentionID;
}
/**
*
* @uml.property name="mIntentionID"
*/
public void setMIntentionID(String intentionID) {
mIntentionID = intentionID;
}
}
CooWS/src/org/coows/util/CooAgentState.java 0000644 0001750 0001750 00000005060 10257017152 021705 0 ustar joshua joshua 0000000 0000000 package org.coows.util;
import java.util.Vector;
/**
* The agent state.
* Holds the info to be dumped to the db
*/
public class CooAgentState
{
/** The agent ID */
private String mAgentID;
/**
* The agent plan library
*
* @uml.property name="mSop"
* @uml.associationEnd multiplicity="(0 1)"
*/
private CooSetOfPlans mSop;
/** The list of known agents */
private Vector mPartners;
/** The retrieval strategy */
private int mRetrievalStrategy;
/** The acquisition strategy */
private int mAcquisitionStrategy;
/**
* Constructor
* @param agentID
* @param sop
* @param partners
* @param retrievalStrategy
* @param acquisitionStrategy
*/
public CooAgentState(
String agentID,
CooSetOfPlans sop,
Vector partners,
int retrievalStrategy,
int acquisitionStrategy)
{
mAgentID = agentID;
mSop = sop;
mPartners = partners;
mRetrievalStrategy = retrievalStrategy;
mAcquisitionStrategy = acquisitionStrategy;
}
/**
*
* @uml.property name="mAgentID"
*/
public String getMAgentID() {
return mAgentID;
}
/**
*
* @uml.property name="mAgentID"
*/
public void setMAgentID(String agentID) {
mAgentID = agentID;
}
/**
*
* @uml.property name="mPartners"
*/
public Vector getMPartners() {
return mPartners;
}
/**
*
* @uml.property name="mPartners"
*/
public void setMPartners(Vector partners) {
mPartners = partners;
}
/**
*
* @uml.property name="mSop"
*/
public CooSetOfPlans getMSop() {
return mSop;
}
/**
*
* @uml.property name="mSop"
*/
public void setMSop(CooSetOfPlans sop) {
mSop = sop;
}
/**
*
* @uml.property name="mAcquisitionStrategy"
*/
public int getMAcquisitionStrategy() {
return mAcquisitionStrategy;
}
/**
*
* @uml.property name="mAcquisitionStrategy"
*/
public void setMAcquisitionStrategy(int as) {
mAcquisitionStrategy = as;
}
/**
*
* @uml.property name="mRetrievalStrategy"
*/
public int getMRetrievalStrategy() {
return mRetrievalStrategy;
}
/**
*
* @uml.property name="mRetrievalStrategy"
*/
public void setMRetrievalStrategy(int retrievalStrategy) {
mRetrievalStrategy = retrievalStrategy;
}
}
CooWS/src/org/coows/util/CooSetOfPlans.java 0000664 0001750 0001750 00000006714 10260242626 021675 0 ustar joshua joshua 0000000 0000000 package org.coows.util;
import org.coows.CooPlan;
import org.coows.ICooDesire;
import java.util.Collection;
import java.util.HashSet;
import java.util.Vector;
/**
* Wrap a set of plans
*/
public class CooSetOfPlans {
/** Contains a */
private HashSet mPlans;
public CooSetOfPlans() {
mPlans = new HashSet();
}
public boolean isEmpty() {
return mPlans.isEmpty();
}
/**
* Add a plan to the set
*
* @param aPlan
*/
public void addPlan(CooPlan aPlan) {
mPlans.add(aPlan);
}
/**
* Add a set of plans to the current set
*
* @param aSop
*/
public void addPlans(CooSetOfPlans aSop) {
mPlans.addAll(aSop.getCollection());
}
/**
* Remove a plan from the set
*
* @param aPlan
* The plan to be removed
*/
public void removePlan(CooPlan aPlan) {
mPlans.remove(aPlan);
}
public CooPlan getAPlan() {
return mPlans.iterator().next();
}
public Collection getCollection() {
return mPlans;
}
/**
* Selects and returns a set of relevant plans for the given agent and
* desire
*
* @param anAgentID
* @param aDesire
* @return
*/
public CooSetOfPlans getRelevantForAgent(String anAgentID,
ICooDesire aDesire) {
CooSetOfPlans res = new CooSetOfPlans();
// Check all the plans in the set
for (CooPlan curr : mPlans) {
// if the agent is trusted
if (curr.getMAccessSpecifier().isTrusted(anAgentID))
// and the trigger of the plan matches with the desire
if (curr.getMTrigger().match(aDesire))
// add the plan to the result set
res.addPlan(curr);
}
return res;
}
/**
* Selects and returns a set of relevant plans for the agent owner
*
* @param aDesire
* @return
*/
public CooSetOfPlans getRelevant(ICooDesire aDesire) {
CooSetOfPlans res = new CooSetOfPlans();
// Check all the plans in the set
for (CooPlan curr : mPlans) {
if (curr.getMTrigger().match(aDesire))
// add the plan to the result set
res.addPlan(curr);
}
return res;
}
/**
* Get the size of the set
*/
public int size() {
return mPlans.size();
}
public String toString() {
String res = "SetOfPlans=[";
for (CooPlan curr : mPlans)
res += " " + curr;
return res + "]";
}
public HashSet getMPlans() {
return mPlans;
}
public void setMPlans(HashSet plans) {
mPlans = plans;
}
public void removePlans(CooSetOfPlans aSop) {
mPlans.removeAll(aSop.getCollection());
}
/**
* Update the set with a collection of provided plans.
* (removing the plans that match with one of the provided)
*
* @param aSop
*/
public void replace(CooSetOfPlans aSop) {
Vector toDel = new Vector();
// Detect all the matching plans already in the set
for (CooPlan curr : mPlans) {
if (!getRelevant(curr.getMTrigger()).isEmpty())
toDel.add(curr);
}
// Remove the matching plans
mPlans.removeAll(toDel);
// Add the new plans
addPlans(aSop);
}
}
CooWS/src/org/coows/util/package.html 0000644 0001750 0001750 00000000107 10204377376 020631 0 ustar joshua joshua 0000000 0000000
CooWS utility classes
CooWS/src/org/coows/work/ 0000755 0001750 0001750 00000000000 10226536574 016360 5 ustar joshua joshua 0000000 0000000 CooWS/src/org/coows/work/CooAbstractWorkerFactory.java 0000644 0001750 0001750 00000002125 10226535354 024144 0 ustar joshua joshua 0000000 0000000 package org.coows.work;
import org.apache.commons.pool.PoolableObjectFactory;
/**
*
*/
public abstract class CooAbstractWorkerFactory
implements PoolableObjectFactory
{
/**
* @see org.apache.commons.pool.PoolableObjectFactory#makeObject()
*/
public abstract Object makeObject() throws Exception;
/**
* @see org.apache.commons.pool.PoolableObjectFactory#destroyObject(java.lang.Object)
*/
public void destroyObject(Object obj) throws Exception
{
if (obj instanceof CooAbstractWorker) {
CooAbstractWorker w = (CooAbstractWorker) obj;
w.setStopped(true);
}
}
/**
* @see org.apache.commons.pool.PoolableObjectFactory#validateObject(java.lang.Object)
*/
public boolean validateObject(Object arg0)
{
return true;
}
/**
* @see org.apache.commons.pool.PoolableObjectFactory#activateObject(java.lang.Object)
*/
public void activateObject(Object arg0) throws Exception
{
}
/**
* @see org.apache.commons.pool.PoolableObjectFactory#passivateObject(java.lang.Object)
*/
public void passivateObject(Object arg0) throws Exception
{
}
}
CooWS/src/org/coows/work/CooWorkerProcessEvent.java 0000644 0001750 0001750 00000002101 10257017153 023457 0 ustar joshua joshua 0000000 0000000 package org.coows.work;
import java.util.LinkedList;
import org.coows.CooAgent;
import org.coows.ICooEvent;
/**
* This worker processes an event local to the agent through a double
* dispatching
*/
public class CooWorkerProcessEvent
extends CooAbstractWorker
{
/**
*
* @uml.property name="mAgent"
* @uml.associationEnd multiplicity="(0 1)"
*/
/*
* The agentID receiver
*/
private CooAgent mAgent;
/**
*
* @uml.property name="mEvent"
* @uml.associationEnd multiplicity="(0 1)"
*/
/*
* The event
*/
private ICooEvent mEvent;
public CooWorkerProcessEvent()
{
super();
}
public synchronized void processEvent(CooAgent anAgent, ICooEvent anEvent)
{
this.mAgent = anAgent;
this.mEvent = anEvent;
handle();
}
protected void execute()
{
mEvent.dd(mAgent);
}
protected void processNextWorkItem(ICooWorkItem w)
{
processEvent(mAgent,(ICooEvent)w);
}
protected LinkedList getQueuedEvents() {
return mAgent.getMEventQueue().getMQueuedEvents();
}
}
CooWS/src/org/coows/work/CooWorkerDispatcher.java 0000644 0001750 0001750 00000002360 10257017151 023132 0 ustar joshua joshua 0000000 0000000 package org.coows.work;
import java.util.LinkedList;
import org.coows.CooAgent;
import org.coows.CooGlobalEventsQueue;
import org.coows.ICooEvent;
import org.coows.engine.CooEngine;
public class CooWorkerDispatcher
extends CooAbstractWorker
{
/**
*
* @uml.property name="mAgent"
* @uml.associationEnd multiplicity="(0 1)"
*/
/*
* The agentID receiver
*/
private CooAgent mAgent;
/**
*
* @uml.property name="mEvent"
* @uml.associationEnd multiplicity="(0 1)"
*/
/*
* The event
*/
private ICooEvent mEvent;
public CooWorkerDispatcher()
{
super();
}
public synchronized void dispatchEvent(CooAgent anAgent, ICooEvent anEvent)
{
this.mAgent = anAgent;
this.mEvent = anEvent;
handle();
}
protected void execute()
{
mAgent.onEvent(mEvent);
}
protected LinkedList getQueuedEvents() {
return CooEngine.getMAgentsManager()
.getMGlobalEventsQueue().getMQueuedEvents();
}
protected void processNextWorkItem(ICooWorkItem w)
{
ICooEvent e = (ICooEvent)w;
dispatchEvent(CooEngine.getMAgentsManager().getAgent(e.getMAgentTO()),
e);
}
}
CooWS/src/org/coows/work/ICooWorkItem.java 0000644 0001750 0001750 00000000074 10226225452 021525 0 ustar joshua joshua 0000000 0000000 package org.coows.work;
public interface ICooWorkItem
{
}
CooWS/src/org/coows/work/CooWorkerProcessEventFactory.java 0000644 0001750 0001750 00000000403 10226536665 025024 0 ustar joshua joshua 0000000 0000000 package org.coows.work;
public class CooWorkerProcessEventFactory extends CooAbstractWorkerFactory
{
public CooWorkerProcessEventFactory()
{
super();
}
public Object makeObject() throws Exception
{
return new CooWorkerProcessEvent();
}
}
CooWS/src/org/coows/work/CooWorkerDispatcherFactory.java 0000644 0001750 0001750 00000000416 10226536624 024471 0 ustar joshua joshua 0000000 0000000 package org.coows.work;
public class CooWorkerDispatcherFactory
extends CooAbstractWorkerFactory
{
public CooWorkerDispatcherFactory()
{
super();
}
public Object makeObject() throws Exception
{
return new CooWorkerDispatcher();
}
}
CooWS/src/org/coows/work/CooAbstractWorker.java 0000644 0001750 0001750 00000006043 10257017153 022613 0 ustar joshua joshua 0000000 0000000 package org.coows.work;
import java.util.LinkedList;
import org.apache.commons.pool.impl.GenericObjectPool;
import org.coows.CooAgent;
import org.coows.CooGlobalEventsQueue;
import org.coows.ICooEvent;
import org.coows.engine.CooEngine;
public abstract class CooAbstractWorker
extends Thread
{
protected boolean running = false;
protected boolean stopped = false;
protected boolean done = true;
protected GenericObjectPool pool = null;
public CooAbstractWorker()
{
this.setDaemon(true);
}
/**
*
* @uml.property name="pool"
*/
public void setPool(GenericObjectPool pool) {
this.pool = pool;
}
/**
*
* @uml.property name="stopped"
*/
public void setStopped(boolean b) {
stopped = b;
}
public void reset()
{
this.done = true;
}
public void run()
{
running = true;
while (!stopped)
{
if (done)
{
synchronized (this)
{
try
{
this.wait();
}
catch (InterruptedException e)
{
stopped = true;
}
}
}
else
{
// there is a task....let us execute it.
try
{
execute();
}
catch (Exception e)
{
}
finally
{
ICooWorkItem w = getNextWorkItem();
if (null != w)
{
processNextWorkItem(w);
}
else
{
reset();
returnToPool();
}
}
}
}
}
protected void handle()
{
this.done = false;
if (!running)
{
// If this is the first time, then kick off the thread.
this.setDaemon(true);
this.start();
}
else
{
// we already have a thread running so wakeup the waiting thread.
this.notifyAll();
}
}
private void returnToPool()
{
if (pool != null)
{
try
{
pool.returnObject(this);
}
catch (Exception e1)
{
}
this.pool = null;
}
}
private ICooWorkItem getNextWorkItem()
{
ICooEvent e = null;
LinkedList qe = getQueuedEvents();
synchronized (qe)
{
if (!qe.isEmpty())
{
e = (ICooEvent) qe.remove(0);
}
}
return e;
}
protected abstract void processNextWorkItem(ICooWorkItem w);
protected abstract void execute();
protected abstract LinkedList getQueuedEvents();
}
CooWS/src/org/coows/CooEventOrdinary.java 0000664 0001750 0001750 00000004600 10264514433 021465 0 ustar joshua joshua 0000000 0000000 package org.coows;
import java.util.Vector;
/**
* The ordinary event
*/
public class CooEventOrdinary
extends CooAbstractEvent {
/**
* The desires
*
* @uml.property name="mDesire"
* @uml.associationEnd multiplicity="(0 1)"
*/
//private Vector mDesires;
private ICooDesire mDesire;
/**
* List of actions to be performed when the desire is achieved
*
* @uml.property name="mSuccessAction"
* @uml.associationEnd multiplicity="(0 1)"
*/
private ICooAction mSuccessAction;
/**
* List of actions to be performed when the desire isn't achieved
*
* @uml.property name="mFailureAction"
* @uml.associationEnd multiplicity="(0 1)"
*/
private ICooAction mFailureAction;
/**
* Constructor
* @param anAgentTO
*/
public CooEventOrdinary(
String anAgentTO,
//Vector desires,
ICooDesire aDesire,
ICooAction aSuccessAction,
ICooAction aFailureAction) {
mAgentTO = anAgentTO;
//mDesires = desires;
mDesire = aDesire;
mSuccessAction = aSuccessAction;
mFailureAction = aFailureAction;
}
/**
* @see org.coows.ICooEvent#dd(org.coows.CooAgent)
*/
public void dd(CooAgent anAgent) {
anAgent.onEventOrdinary(this);
}
public String toString() {
return "EventOrdinary("+mAgentTO+")";
}
/**
*
* @uml.property name="mFailureAction"
*/
public ICooAction getMFailureAction() {
return mFailureAction;
}
/**
*
* @uml.property name="mFailureAction"
*/
public void setMFailureAction(ICooAction failureAction) {
mFailureAction = failureAction;
}
/**
*
* @uml.property name="mSuccessAction"
*/
public ICooAction getMSuccessAction() {
return mSuccessAction;
}
/**
*
* @uml.property name="mSuccessAction"
*/
public void setMSuccessAction(ICooAction successAction) {
mSuccessAction = successAction;
}
public ICooDesire getMDesire() {
return mDesire;
}
public void setMDesire(ICooDesire desire) {
mDesire = desire;
}
/*
public Vector getMDesires() {
return mDesires;
}
public void setMDesires(Vector desires) {
mDesires = desires;
}
*/
}
CooWS/src/org/coows/coows-i.ucd 0000644 0001750 0001750 00000146060 10257031230 017441 0 ustar joshua joshua 0000000 0000000
CooWS/src/org/coows/CooPlan.java 0000664 0001750 0001750 00000004406 10260251750 017566 0 ustar joshua joshua 0000000 0000000 package org.coows;
/**
* A CooWS plan is defined by the tuple
* (plan ID, trigger, body, access specifier)
*
*/
public class CooPlan {
/**
* The unique plan identifier
*/
private String mPlanID;
/**
* The trigger of the plan
*
* @uml.property name="mTrigger"
* @uml.associationEnd multiplicity="(0 1)"
*/
private ICooDesire mTrigger;
/**
*
* The name of the service provided by the bpel process that implements the
* body of the plan
*/
private String mBodyID;
/**
* The access specifier for the plan
*/
private ICooAccessSpecifier mAccessSpecifier;
/**
* Constructor
*
*/
public CooPlan() {
}
/**
* Constructor
*
* @param plandID
* @param trigger
* @param bpelPlan
* @param accessSpecifier
*/
public CooPlan(String aPlanID, ICooDesire aTrigger, String aServiceName,
ICooAccessSpecifier aAccessSpecifier) {
mPlanID = aPlanID;
mTrigger = aTrigger;
mBodyID = aServiceName;
mAccessSpecifier = aAccessSpecifier;
}
/**
*
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return mPlanID.hashCode();
}
public boolean equals(Object o) {
if (o instanceof CooPlan)
return mPlanID.equals(((CooPlan)o).getMPlanID());
else
return false;
}
public String toString() {
String res = "(PLANID: ";
res += this.mPlanID;
res += (", TRIGGER=" + mTrigger);
res += (", BODY=" + mBodyID);
res += (", ACCSPEC=" + mAccessSpecifier);
res += ")";
return res;
}
/**
*
* @uml.property name="mPlandID"
*/
public String getMPlanID() {
return mPlanID;
}
/**
*
* @uml.property name="mPlandID"
*/
public void setMPlanID(String planID) {
mPlanID = planID;
}
/**
*
* @uml.property name="mTrigger"
*/
public ICooDesire getMTrigger() {
return mTrigger;
}
/**
*
* @uml.property name="mTrigger"
*/
public void setMTrigger(ICooDesire trigger) {
mTrigger = trigger;
}
public ICooAccessSpecifier getMAccessSpecifier() {
return mAccessSpecifier;
}
public void setMAccessSpecifier(
ICooAccessSpecifier accessSpecifier) {
mAccessSpecifier = accessSpecifier;
}
public String getMServiceName() {
return mBodyID;
}
public void setMServiceName(String serviceName) {
mBodyID = serviceName;
}
}
CooWS/src/org/coows/CooEventRemote.java 0000644 0001750 0001750 00000002221 10257017152 021122 0 ustar joshua joshua 0000000 0000000 package org.coows;
/**
* Define the interface for the remote events
* (a sort of wrapper)
*/
public class CooEventRemote {
/**
*
* @uml.property name="mEvent"
* @uml.associationEnd multiplicity="(0 1)"
*/
private ICooEvent mEvent;
private String mSourceHost;
/** Constructor */
public CooEventRemote() {
}
/** Constructor */
public CooEventRemote(ICooEvent anEvent, String anHost) {
mEvent = anEvent;
mSourceHost = anHost;
}
/**
* Modifier
*
* @uml.property name="mEvent"
*/
public ICooEvent getMEvent() {
return mEvent;
}
/**
* Modifier
*
* @uml.property name="mEvent"
*/
public void setMEvent(ICooEvent event) {
mEvent = event;
}
/** Modifier */
public String getMAgentTO() {
return mEvent.getMAgentTO();
}
/**
*
* @uml.property name="mSourceHost"
*/
public String getMSourceHost() {
return mSourceHost;
}
/**
*
* @uml.property name="mSourceHost"
*/
public void setMSourceHost(String sourceHost) {
mSourceHost = sourceHost;
}
}
CooWS/src/org/coows/CooIntention.java 0000644 0001750 0001750 00000007554 10260271704 020651 0 ustar joshua joshua 0000000 0000000 package org.coows;
import java.util.Vector;
import org.coows.engine.CooEngine;
/**
* The intention
* An intention is a stack of "instance records"
* (@see org.coows.CooInstanceRecord)
*/
public class CooIntention {
private String mIntentionID;
/**
*
* @uml.property name="mSuccessActions"
* @uml.associationEnd multiplicity="(0 1)"
*/
private ICooAction mSuccessActions;
/**
*
* @uml.property name="mFailureActions"
* @uml.associationEnd multiplicity="(0 1)"
*/
private ICooAction mFailureActions;
private Vector mStack;
private Vector mStackRecordIDs;
private int mCounter = 0;
private String mAgentOwner;
private boolean mCompleted;
/**
* Constructor
*
*/
public CooIntention(
String anAgentID,
String anIntentionID,
ICooAction aSuccessAction,
ICooAction aFailureAction) {
mAgentOwner = anAgentID;
mIntentionID = anIntentionID;
mSuccessActions = aSuccessAction;
mFailureActions = aFailureAction;
mStack = new Vector();
mStackRecordIDs = new Vector();
mCompleted = false;
}
/**
* Push a new instance record on top (occurs on "achieve" event)
* @param anInstanceRecord
*/
public String push(CooInstanceRecord anInstanceRecord) {
synchronized (mStack) {
if (mStack.isEmpty())
anInstanceRecord.setMRefToPrev(null);
else
anInstanceRecord.setMRefToPrev(mStack.lastElement());
anInstanceRecord.setMRefToIntention(this);
mStack.add(anInstanceRecord);
mStackRecordIDs.add(String.valueOf(mCounter));
return String.valueOf(mCounter++);
}
}
public void checkSuspended() {
int pos = 0;
boolean isFailed = false;
synchronized (top().mIsSuspended) {
if (top().mIsSuspended.booleanValue() && top().isInTimeout()) {
pos = mStack.indexOf(top());
mStack.remove(pos);
isFailed = true;
}
}
if (isFailed)
if (pos==0)
fail();
else {
CooInstanceRecord prevInst =
(CooInstanceRecord) mStack.elementAt(pos-1);
prevInst.failCurrentPlan();
}
}
/**
*
* @uml.property name="mAgentOwner"
*/
public String getMAgentOwner() {
return mAgentOwner;
}
/**
*
* @uml.property name="mIntentionID"
*/
public String getMIntentionID() {
return mIntentionID;
}
public void fail() {
mFailureActions.exec();
mCompleted = true;
}
public void dispatchPlanOutcome(CooEventPlanOutcome anEvent) {
if (anEvent.isSuccess()) {
mStack.remove(top());
if (mStack.size() == 0) {
mSuccessActions.exec();
mCompleted = true;
} else
CooEngine.getMProcessesManager().dispatchAchieved(mAgentOwner,
mIntentionID, top().mCurrentRunningPlan.getMPlanID());
} else
top().failCurrentPlan();
}
public void dispatchProvided(CooEventProvided anEvent) {
CooInstanceRecord dest;
if (mStackRecordIDs.contains(anEvent.getMReqID().getMInstanceID())) {
dest = mStack.get(mStackRecordIDs.indexOf(
anEvent.getMReqID().getMInstanceID()));
dest.provided(anEvent.getMProvidedPlans());
}
}
public CooInstanceRecord top() {
return mStack.lastElement();
}
public boolean isCompleted() {
return mCompleted;
}
}
CooWS/src/org/coows/CooEventProvided.java 0000664 0001750 0001750 00000004315 10257017150 021451 0 ustar joshua joshua 0000000 0000000 package org.coows;
import org.coows.util.CooRequestID;
import org.coows.util.CooSetOfPlans;
/**
* The event for "provided" op
*/
public class CooEventProvided
extends CooAbstractEvent {
/**
* The request ID
*
* @uml.property name="mReqID"
* @uml.associationEnd multiplicity="(0 1)"
*/
private CooRequestID mReqID;
/** The agent sender */
private String mAgentFROM;
/**
* The set of provided plans
*
* @uml.property name="mProvidedPlans"
* @uml.associationEnd multiplicity="(0 1)"
*/
private CooSetOfPlans mProvidedPlans;
/**
* Constructor
*
*/
public CooEventProvided() {
mAgentTO = "";
mReqID = null;
mAgentFROM = "";
mProvidedPlans = new CooSetOfPlans();
}
/**
* Constructor
* @param anAgentFROM
* @param anAgentTO
* @param aReqID
* @param aSop
*/
public CooEventProvided(String anAgentFROM, String anAgentTO,
CooRequestID aReqID, CooSetOfPlans aSop) {
mReqID = aReqID;
mAgentFROM = anAgentFROM;
mAgentTO = anAgentTO;
mProvidedPlans = aSop;
}
/**
*
* @uml.property name="mAgentFROM"
*/
public void setMAgentFROM(String agentProvider) {
mAgentFROM = agentProvider;
}
/**
*
* @uml.property name="mAgentFROM"
*/
public String getMAgentFROM() {
return mAgentFROM;
}
/**
*
* @uml.property name="mProvidedPlans"
*/
public void setMProvidedPlans(CooSetOfPlans providedPlans) {
mProvidedPlans = providedPlans;
}
/**
*
* @uml.property name="mProvidedPlans"
*/
public CooSetOfPlans getMProvidedPlans() {
return mProvidedPlans;
}
/**
*
* @uml.property name="mReqID"
*/
public void setMReqID(CooRequestID reqID) {
mReqID = reqID;
}
/**
*
* @uml.property name="mReqID"
*/
public CooRequestID getMReqID() {
return mReqID;
}
public String toString() {
return "EventProvided("+mAgentFROM+","
+mAgentTO+","+mReqID+","+mProvidedPlans+")";
}
/**
*
* @see org.coows.ICooEvent#dd(org.coows.CooAgent)
*/
public void dd(CooAgent anAgent) {
anAgent.onEventProvided(this);
}
}
CooWS/src/org/coows/ICooDesire.java 0000664 0001750 0001750 00000000602 10245674553 020227 0 ustar joshua joshua 0000000 0000000 package org.coows;
/**
* Interface for Desire implementations
*/
public interface ICooDesire {
/** Modifier for the mDes field */
//public String getMDes();
/** Modifier for the mDes field */
//public void setMDes(String aDes);
/**
* Test the match between two desire objects
* (usually a plan trigger and a desire)
*/
public boolean match(ICooDesire aDes);
}
CooWS/src/org/coows/CooAbstractEvent.java 0000664 0001750 0001750 00000001037 10257017151 021437 0 ustar joshua joshua 0000000 0000000 package org.coows;
/**
* Base class for the events impl
*/
public abstract class CooAbstractEvent
implements ICooEvent {
protected String mAgentTO;
/**
*
* @see org.coows.ICooEvent#dd(org.coows.CooAgent)
*/
public abstract void dd(CooAgent anAgent);
/**
*
* @uml.property name="mAgentTO"
*/
public String getMAgentTO() {
return mAgentTO;
}
/**
*
* @uml.property name="mAgentTO"
*/
public void setMAgentTO(String agentTo) {
mAgentTO = agentTo;
}
}
CooWS/src/org/coows/engine/ 0000755 0001750 0001750 00000000000 10231226535 016630 5 ustar joshua joshua 0000000 0000000 CooWS/src/org/coows/engine/CooAgentsManager.java 0000644 0001750 0001750 00000011537 10264751232 022662 0 ustar joshua joshua 0000000 0000000 package org.coows.engine;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.coows.CooAgent;
import org.coows.CooEventProvided;
import org.coows.CooEventRemote;
import org.coows.CooEventRequested;
import org.coows.CooGlobalEventsQueue;
import org.coows.ICooEvent;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
/**
* The manager of local agents
*/
public class CooAgentsManager {
/**
* Logger for this class
*/
private static final Log logger = LogFactory.getLog(CooAgentsManager.class);
/**
* A table holding the ref to local agents
*/
private Hashtable mAgents;
/**
* The queue where are stored the incoming events waiting to be dispatched
*
* @uml.property name="mGlobalEventsQueue"
* @uml.associationEnd multiplicity="(0 1)"
*/
private CooGlobalEventsQueue mGlobalEventsQueue;
/**
* Restore the agents with the last saved state and initialize all local
* variables (thread pool and global event queue)
*
* @param aConf
* @throws CooException
*/
public CooAgentsManager(CooEngineConfiguration aConf)
throws CooException {
if (logger.isDebugEnabled()) {
logger.debug("CooAgentsManager() - "
+ "initializing Agents Manager structures");
}
// Restore the agents
mAgents = CooPersistenceManager.restoreAgents(aConf);
// Create the global events queue
mGlobalEventsQueue = new CooGlobalEventsQueue();
if (logger.isDebugEnabled()) {
logger.debug("CooAgentsManager() - Agents Manager loaded!");
}
}
/**
* Start the agents execution
*
*/
public void startAgents() {
for (Iterator i = mAgents.values().iterator();i.hasNext();) {
i.next().start();
}
}
/**
* Handle incoming events throuth the global events queue
*
*
* @param anEvent
* @throws CooException
*/
public void dispatchEvent(ICooEvent anEvent) {
if (logger.isDebugEnabled()) {
logger.debug("dispatchEvent(anEvent = " + anEvent
+ ") - received new incoming event");
}
mGlobalEventsQueue.enqueue(anEvent);
}
/**
* Dispatch an incoming remote event
* On event requested the agents directory cache is updated
* On event provided the processes manager is notified on the source host
*
* @param anEvent
* @throws CooException
*/
public void dispatchEvent(CooEventRemote anEvent) {
if (anEvent.getMEvent() instanceof CooEventRequested)
CooEngine.getAgentsDirectory().updateCache(
((CooEventRequested) anEvent.getMEvent()).getMAgentFROM(),
anEvent.getMSourceHost());
else
if (anEvent.getMEvent() instanceof CooEventProvided)
CooEngine.getMProcessesManager().updateNoLocal(
((CooEventProvided) anEvent.getMEvent())
.getMProvidedPlans(), anEvent.getMSourceHost());
this.dispatchEvent(anEvent.getMEvent());
}
/**
* Shutdown the agents manager
* Serialize the current agents states to the db and halt the agents
* execution cicle
*
* @param aConf
*/
public void shutdown(CooEngineConfiguration aConf) {
Iterator curr;
try {
// Clear the global queue
mGlobalEventsQueue.clear();
// Notify the agents
for (curr = mAgents.values().iterator();curr.hasNext();)
curr.next().prepare4shutdown();
// Serialize agents state to the db
CooPersistenceManager.serializeAgents(aConf, mAgents.values());
// Halt the agents execution
for (curr = mAgents.values().iterator(); curr.hasNext();) {
curr.next().shutdown();
}
if (logger.isDebugEnabled()) {
logger.debug("shutdown() done!");
}
} catch (CooException e) {
if (logger.isErrorEnabled()) {
logger.error("shutdown() - Encountered an error while" +
"shuting down the Agents Manager!",e);
}
}
}
/**
* getter
* @param anAgentID
* @return
*/
public CooAgent getAgent(String anAgentID) {
return (CooAgent) mAgents.get(anAgentID);
}
public Set getAgentsIDs() {
return mAgents.keySet();
}
/**
* getter
* @uml.property name="mGlobalEventsQueue"
*/
public CooGlobalEventsQueue getMGlobalEventsQueue() {
return mGlobalEventsQueue;
}
}
CooWS/src/org/coows/engine/CooEngine.java 0000664 0001750 0001750 00000010266 10260241136 021344 0 ustar joshua joshua 0000000 0000000 package org.coows.engine;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Singleton class
*/
public class CooEngine {
/**
* Logger for this class
*/
private static final Log logger = LogFactory.getLog(CooEngine.class);
public static final String CATALINA_HOME =
System.getProperties().getProperty("catalina.home");
public static final String DEFAULT_CONFIG_DIR = CATALINA_HOME + "/conf";
private static final String DEFAULT_CONFIG_FILE = "cooEngineConf.xml";
/**
* The in memory representation of the engine configuration
*
* @uml.property name="mConfig"
* @uml.associationEnd multiplicity="(0 1)"
*/
private static CooEngineConfiguration mConfig;
/**
* The agents manager
*
* @uml.property name="mAgentsManager"
* @uml.associationEnd multiplicity="(0 1)"
*/
private static CooAgentsManager mAgentsManager;
/**
* The agents directory
*
* @uml.property name="mAgentsDirectory"
* @uml.associationEnd multiplicity="(0 1)"
*/
private static CooAgentsDirectory mAgentsDirectory;
/**
* The manager of the bpel processes
*
* @uml.property name="mProcessesManager"
* @uml.associationEnd multiplicity="(0 1)"
*/
private static CooBpelProcessesManager mProcessesManager;
public static CooAgentsDirectory getAgentsDirectory() {
return mAgentsDirectory;
}
/**
*
* @uml.property name="mAgentsManager"
*/
public static CooAgentsManager getMAgentsManager() {
return mAgentsManager;
}
/**
*
* @uml.property name="mConfig"
*/
public static CooEngineConfiguration getMConfig() {
return mConfig;
}
public static void init() {
init(DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_DIR);
}
// Convenience method for debug purpose
public static void initTEMP(String configFile, String configDir) {
try {
mConfig = new CooEngineConfiguration(configFile, configDir);
} catch (Exception e) {
}
}
/**
* Initialize all the CooWS modules and start the execution
*
* @param configFile
* @param configDir
*/
public static void init(String configFile, String configDir) {
if (logger.isDebugEnabled())
{
logger.debug("init() - Initializing CooWS engine components");
}
try {
// Load the configuration file
mConfig = new CooEngineConfiguration(configFile, configDir);
// PopulateDB.populateProcessTable(mConfig);
// Initialize the BPEL Processes Manager
mProcessesManager = new CooBpelProcessesManager(mConfig);
// Initialize the Agents Manager
mAgentsManager = new CooAgentsManager(mConfig);
// CooPersistenceManager.restoreAgents(mConfig);
// Initialize the Agents Directory Manager
mAgentsDirectory = new CooAgentsDirectory(mConfig);
// Update the directory with the local agents
mAgentsDirectory.publishLocalAgents(mAgentsManager.getAgentsIDs());
// Start the agents execution
mAgentsManager.startAgents();
if (logger.isDebugEnabled()) {
logger.debug("init() - CooWS engine started!");
}
} catch (Exception e) {
if (logger.isErrorEnabled())
{
logger.error("init() - Failed to start the CooWS engine!", e);
}
}
}
/**
* Shutdown the agents
* @throws CooException
*/
public static void shutdown() throws CooException {
if (logger.isDebugEnabled())
{
logger.debug("shutdown() - Halting the CooWS engine");
}
mAgentsDirectory.shutdown();
mAgentsManager.shutdown(mConfig);
mProcessesManager.shutdown(mConfig);
if (logger.isDebugEnabled())
{
logger.debug("shutdown() - " +
"CooWS engine has been successfully shutdown!");
}
}
/**
*
* @uml.property name="mProcessesManager"
*/
public static CooBpelProcessesManager getMProcessesManager() {
return mProcessesManager;
}
}
CooWS/src/org/coows/engine/CooEngineConfiguration.java 0000664 0001750 0001750 00000005571 10240171162 024076 0 ustar joshua joshua 0000000 0000000 package org.coows.engine;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jaxen.JaxenException;
import org.jaxen.XPath;
import org.jaxen.dom.DOMXPath;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
/**
*
*/
public class CooEngineConfiguration {
/**
* Logger for this class
*/
private static final Log logger = LogFactory
.getLog(CooEngineConfiguration.class);
private Document doc;
private File configFile;
/**
* @param configFile
* @param configDir
*
* @throws CooException
*/
public CooEngineConfiguration(String configFileName, String configDir)
throws CooException {
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
configFile = new File(configDir, configFileName);
doc = builder.parse(configFile);
if (logger.isDebugEnabled()) {
logger.debug("CooEngineConfiguration() - " +
"CooWS engine configuration loaded!");
}
} catch (Exception e) {
throw new CooException("[CooEngineConfiguration.CONSTRUCTOR]"
+ " Error reading config file: " + e.getMessage());
}
}
/**
* Given a lookup xpath and an attribute name, returns the value
* of that attribute.
*
* @param xpath
* an XPath expression
* @param attrName
* an attribute name
*
* @return the value of the text inside the specified element
*/
public String getAttr(String xpath, String attrName) throws CooException {
try {
return get(xpath + "/@" + attrName);
} catch (Exception e) {
throw new CooException(
"[CooEngine ERROR] unable to get the value of the value "
+ xpath + "/@" + attrName + " from config file");
}
}
/**
* Given a lookup xpath, returns the value of the text inside
* the specified element.
*
* @param xpath
* an XPath expression
*
* @return the value of the text inside the specified element
*/
public String getText(String xpath) throws CooException {
try {
return get(xpath + "/text()[1]");
} catch (Exception e) {
throw new CooException("[CooEngine ERROR] unable to get the value "
+ xpath + " from config file");
}
}
/**
* Given an xpath, returns the value of that element.
*
* @param xpath
* an XPath expression
*
* @return the value
*/
public String get(String xpath) throws CooException {
XPath xp;
try {
xp = new DOMXPath(xpath);
Node node = (Node) xp.selectSingleNode(doc);
return node.getNodeValue().trim();
} catch (JaxenException e) {
throw new CooException("[CooEngine ERROR] unable to get the value "
+ xpath + " from config file");
}
}
}
CooWS/src/org/coows/engine/CooBpelProcessesManager.java 0000644 0001750 0001750 00000014365 10261250066 024210 0 ustar joshua joshua 0000000 0000000 package org.coows.engine;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.coows.CooBpelProcessParameters;
import org.coows.CooEventPlanOutcome;
import org.coows.CooPlan;
import org.coows.ICooBpelProcess;
import org.coows.util.CooSetOfPlans;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
/**
* The Manager of the local BPEL Processes
*
*/
public class CooBpelProcessesManager {
/**
* Logger for this class
*/
private static final Log logger =
LogFactory.getLog(CooBpelProcessesManager.class);
/**
* The archive of local BPEL processes The table maps for each serviceName
* the corresponding BPEL process
*/
private Hashtable mProcesses;
/**
* This table holds the info necessary for the retrieval of remote processes
* For each serviceName we have a list of hostnames wich coud supply the
* BPEL process associated
*/
private Hashtable> mNoLocalProcesses;
/**
* The local hostname
*/
private String mHostname;
/**
* List of serviceName currently deployed
*/
private Vector mProcessesDeployed;
/**
* Constructor
*
* @param aConf
* The engine configuration
* @throws CooException
*/
public CooBpelProcessesManager(CooEngineConfiguration aConf)
throws CooException {
mProcesses = CooPersistenceManager.restoreBpelProcesses(aConf);
mProcessesDeployed = new Vector();
mNoLocalProcesses = new Hashtable>();
try {
// retrieve the hostname
mHostname = InetAddress.getLocalHost().getHostName();
}
catch (UnknownHostException e) {
mHostname = "localhost";
System.out.println("[CooBpelProcessManager.init] WARNING: "
+ "unable to resolv hostname! Using localhost");
}
if (logger.isInfoEnabled()) {
logger.info("CooBpelProcessesManager() - "
+ "BPEL Processes Manager Loaded!");
}
}
/**
* Invoke a process on demand
*
* @param anAgentID
* The agent requestor
* @param aServiceName
* The service name
*/
public void invokeProcess(String anAgentID, String anIntentionID,
String aServiceName) {
if (logger.isDebugEnabled()) {
logger.debug("runProcess(agentID = " + anAgentID + ", "
+ "serviceName = " + aServiceName + ")");
}
// If the process is not stored locally and doesn't appear
// among the remote provided processes
if (!mProcesses.containsKey(aServiceName)
&& !mNoLocalProcesses.containsKey(aServiceName)) {
if (logger.isErrorEnabled()) {
logger.error("runProcess() Error! " +
"Trying to run unknown process!!! " + aServiceName, null);
}
return;
}
// If the process is stored on a remote node
if (!mProcesses.containsKey(aServiceName)
&& mNoLocalProcesses.contains(aServiceName)) {
// Retrieve the remote BPEL process
String remoteHost =
mNoLocalProcesses.get(aServiceName).lastElement();
// TODO send to the remote host the request
}
ICooBpelProcess proc = (ICooBpelProcess) mProcesses.get(aServiceName);
try {
if (!mProcessesDeployed.contains(aServiceName)) {
// Deploy the process
proc.deploy();
mProcessesDeployed.add(aServiceName);
}
// Invoke the process
proc.invoke(
new CooBpelProcessParameters(mHostname, anAgentID,anIntentionID));
} catch (CooException e) {
logger.error("runProcess(serviceName = " + aServiceName
+ ") - Failed to invoke process ", e);
// Notify the agent requester
CooEngine.getMAgentsManager().dispatchEvent(
new CooEventPlanOutcome(anAgentID,anIntentionID,false));
}
}
/**
*
* @param aServiceName
* @return
* @throws CooException
*/
public ICooBpelProcess getProcess(String aServiceName)
throws CooException {
if (mProcesses.containsKey(aServiceName))
return (ICooBpelProcess) mProcesses.get(aServiceName);
else
throw new CooException("Process " + aServiceName + "not found!");
}
/**
* Keep trace of the host where could be retrieved the BPEL processes
* of the plans retrieved remotely
*
* @param aSop
* @param anHostname
*/
public void updateNoLocal(CooSetOfPlans aSop, String anHostname) {
CooPlan curr;
Vector aux;
for (Iterator i = aSop.getMPlans().iterator(); i.hasNext();) {
curr = i.next();
if (mProcesses.containsKey(curr.getMPlanID()))
continue;
else {
aux = (Vector) mNoLocalProcesses.get(curr.getMPlanID());
if (null == aux) aux = new Vector();
aux.add(anHostname);
mNoLocalProcesses.put(curr.getMPlanID(), aux);
}
}
}
/**
* Shutdown the Manager
* (undeploys all the processes and stores them back to the db)
*
* @param aConf
* @throws CooException
*/
public void shutdown(CooEngineConfiguration aConf)
throws CooException {
for (Iterator i = mProcessesDeployed.iterator(); i.hasNext();)
mProcesses.get(i.next()).undeploy();
CooPersistenceManager.serializeProcesses(aConf, mProcesses.values());
if (logger.isDebugEnabled()) {
logger.debug("shutdown() done!");
}
}
/**
* Dispatch an achieved message to a suspended process
* @param planID
*/
public void dispatchAchieved(String anAgentID, String anIntentionID,
String aServiceName) {
}
}
CooWS/src/org/coows/engine/CooAgentsDirectory.java 0000664 0001750 0001750 00000040253 10264515133 023251 0 ustar joshua joshua 0000000 0000000 package org.coows.engine;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
import org.coows.CooAccessSpecifierOnlyTrusted;
import org.coows.CooAccessSpecifierPrivate;
import org.coows.CooAccessSpecifierPublic;
import org.coows.CooBpelProcessBpr;
import org.coows.CooDesire;
import org.coows.CooEventProvided;
import org.coows.CooEventRequested;
import org.coows.CooPlan;
import org.coows.CooEventRemote;
import org.coows.ICooEvent;
import org.coows.ser.CooBprFileDeserializerFactory;
import org.coows.ser.CooBrpFileSerializerFactory;
import org.coows.util.CooBprFile;
import org.coows.util.CooSetOfPlans;
import org.uddi4j.UDDIException;
import org.uddi4j.client.UDDIProxy;
import org.uddi4j.datatype.Name;
import org.uddi4j.datatype.business.BusinessEntity;
import org.uddi4j.response.AuthToken;
import org.uddi4j.response.BusinessDetail;
import org.uddi4j.response.BusinessInfo;
import org.uddi4j.response.BusinessList;
import org.uddi4j.transport.TransportException;
import org.uddi4j.transport.TransportFactory;
import org.uddi4j.util.DiscoveryURL;
import org.uddi4j.util.DiscoveryURLs;
import org.uddi4j.util.FindQualifier;
import org.uddi4j.util.FindQualifiers;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
/**
* Interface the CooWS engine with the UDDI agents repository
*/
public class CooAgentsDirectory {
/**
* Logger for this class
*/
private static final Log logger =
LogFactory.getLog(CooAgentsDirectory.class);
private final static QName REMOTEEVENT_QNAME =
new QName("urn:coows", "RemoteEvent");
/**
* A cache for the UDDI repository
*
*/
private static Hashtable mUDDIRepositoryCache;
/**
* The local hostname
*/
private final String mHostname;
/**
* The UDDI Proxy (see the juddi doc)
*/
private UDDIProxy mUDDIProxy;
/**
* The Auth token (see the juddi doc)
*/
private AuthToken mAuthToken;
/**
* Default constructor
*/
public CooAgentsDirectory(CooEngineConfiguration aConfig)
throws CooException {
try {
mHostname = InetAddress.getLocalHost().getHostName();
}
catch (UnknownHostException e) {
throw new CooException("[CooAgentsDirectory] init failed! "
+ "Unable to resolv hostname!");
}
initUDDI(aConfig);
mUDDIRepositoryCache = new Hashtable();
if (logger.isDebugEnabled()) {
logger.debug("CooAgentsDirectory() - Agents Directory Loaded!");
}
}
/**
* Find an agent location through the UDDI registry
*
* @param anAgentID
* the agentID
*
* @return the host where the agent is hosted
*
* @throws TransportException
* @throws UDDIException
*/
private String getAgentLocation(String anAgentID)
throws UDDIException, TransportException {
String agentHostedBy;
if (mUDDIRepositoryCache.containsKey(anAgentID)) {
// retrieve the agent info from the local cache
agentHostedBy = mUDDIRepositoryCache.get(anAgentID);
}
else {
// Retrieve the agent info from the remote UDDI registry
// creating vector of Name Object
Vector names = new Vector();
names.add(new Name(anAgentID));
// Setting FindQualifiers to 'exactNameMatch'
FindQualifiers findQualifiers = new FindQualifiers();
Vector qualifier = new Vector();
qualifier.add(new FindQualifier("exactNameMatch"));
findQualifiers.setFindQualifierVector(qualifier);
// Find the agent location
BusinessList businessList = mUDDIProxy.find_business(names, null,
null, null, null, findQualifiers, 2);
Vector businessInfoVector =
businessList.getBusinessInfos().getBusinessInfoVector();
if (businessInfoVector.size() > 1) {
logger.warn("agent " + anAgentID +
" is published twice!", null);
}
// Retrieve the agent's info
BusinessInfo bi = (BusinessInfo) businessInfoVector.elementAt(0);
BusinessDetail bd =
mUDDIProxy.get_businessDetail(bi.getBusinessKey());
BusinessEntity be = (BusinessEntity)
bd.getBusinessEntityVector().elementAt(0);
agentHostedBy = be.getDiscoveryURLs().get(0).getText();
// Update the local cache for future lookups
mUDDIRepositoryCache.put(anAgentID, agentHostedBy);
}
if (logger.isDebugEnabled()) {
logger.debug("getAgentLocation() - retrieved agent's location : "
+ "agentHostedBy = " + agentHostedBy);
}
return agentHostedBy;
}
/**
* Publish the local agents to the UDDI registry
*
* @param config
* @param enumeration
*
* @throws CooException
*/
public void publishLocalAgents(Set agents)
throws CooException {
publishAgents2UDDI(agents);
}
/**
* Send an event to an agent
*
* @param mAgents
* @param anEvent
*/
public void sendEvent(ICooEvent anEvent) {
if (logger.isDebugEnabled()) {
logger.debug("sendEvent() - Dispatching event: " + anEvent);
}
Dispatcher d = new Dispatcher(anEvent);
}
/**
* Send the same event to different agents
*
* @param anEvent
* @param dests
*/
public void sendEvent(CooEventRequested anEvent, Vector dests) {
if (logger.isDebugEnabled()) {
logger.debug("sendEvent() - Dispatching event " + anEvent
+ " to agents " + dests);
}
Dispatcher d = new Dispatcher(anEvent, dests);
}
/**
* Unregister agents from the UDDI server
*
* @param agents
*/
public void unregisterAgentsFromUDDI(Set agents) {
// TODO
}
/**
* Shutdown the Agents Directory
*
*/
public void shutdown() {
unregisterAgentsFromUDDI(CooEngine.getMAgentsManager().getAgentsIDs());
}
/**
* Connect to the UDDI server and get an auth token
*
* @throws CooException
*/
private void initUDDI(CooEngineConfiguration aConfig)
throws CooException {
try {
String aUDDInquiryURL = aConfig
.getText("/config/agentsDirConf/uddi-registry/inquiry-url");
String aUDDIpublishURL = aConfig
.getText("/config/agentsDirConf/uddi-registry/publish-url");
System.setProperty(TransportFactory.PROPERTY_NAME,
"org.uddi4j.transport.ApacheAxisTransport");
System.setProperty("org.uddi4j.logEnabled", "false");
System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
java.security.Security.addProvider((java.security.Provider) Class
.forName("com.sun.net.ssl.internal.ssl.Provider")
.newInstance());
mUDDIProxy = new UDDIProxy();
mUDDIProxy.setInquiryURL(aUDDInquiryURL);
mUDDIProxy.setPublishURL(aUDDIpublishURL);
mAuthToken = mUDDIProxy.get_authToken(
aConfig.getText("/config/agentsDirConf/uddi-registry/userid"),
aConfig.getText("/config/agentsDirConf/uddi-registry/password"));
}
catch (MalformedURLException e) {
throw new CooException("[CooAgentsDirectory] init failed! "
+ "UDDI server URL malformed! check the config file!");
}
catch (UDDIException e) {
throw new CooException("[CooAgentsDirectory] init failed! "
+ "Unable to get an authorization token from "
+ "the remote UDDI registry " + e);
}
catch (TransportException e) {
throw new CooException("[CooAgentsDirectory] init failed! "
+ "Unable to get an authorization token from "
+ "the remote UDDI registry " + e);
}
catch (ClassNotFoundException e) {
throw new CooException("[CooAgentsDirectory] init failed! "
+ "Error configuring JSSE provider. "
+ "Make sure JSSE is in classpath! " + e);
}
catch (InstantiationException e) {
throw new CooException("[CooAgentsDirectory] init failed! "
+ "Error configuring JSSE provider! " + e);
}
catch (IllegalAccessException e) {
throw new CooException("[CooAgentsDirectory] init failed! "
+ "Error configuring JSSE provider! " + e);
}
}
/**
* Publish the local agents to the UDDI server
*
* @param agents
* @throws CooException
*/
private void publishAgents2UDDI(Set agents)
throws CooException {
Vector localAgents = new Vector();
BusinessEntity be;
String agentID;
DiscoveryURLs dus = new DiscoveryURLs();
dus.add(new DiscoveryURL(mHostname, "hostedBy"));
for (Iterator i = agents.iterator(); i.hasNext();) {
agentID = (String) i.next();
be = new BusinessEntity("", agentID);
be.setDiscoveryURLs(dus);
localAgents.add(be);
// Add the local agents to the UDDI repository cache
mUDDIRepositoryCache.put(agentID, "localhost");
}
try {
BusinessDetail bd = mUDDIProxy.save_business(mAuthToken
.getAuthInfoString(), localAgents);
System.out.println("[CooAgentsDirectory] "
+ "Local agents registered to UDDI registry!");
}
catch (UDDIException e) {
throw new CooException(
"[CooAgentsDirectory] Error (UDDIException) "
+ "publishing local agents to UDDI " + e);
}
catch (TransportException e) {
throw new CooException(
"[CooAgentsDirectory] Error (TransportException) "
+ "publishing local agents to UDDI " + e);
}
}
/**
* Keep the cache updated
*
* @param anAgentID
* @param anHostname
*/
public void updateCache(String anAgentID, String anHostname) {
mUDDIRepositoryCache.put(anAgentID, anHostname);
}
/**
* A dispatcher (beta version, use the common-pool!)
*/
class Dispatcher extends Thread {
/**
* Logger for this class
*/
private final Log logger = LogFactory.getLog(Dispatcher.class);
Vector mAgents;
/**
*
* @uml.property name="mEvent"
* @uml.associationEnd multiplicity="(0 1)"
*/
ICooEvent mEvent;
public Dispatcher(ICooEvent e) {
super(e.toString());
mAgents = new Vector();
mAgents.add(e.getMAgentTO());
mEvent = e;
start();
}
public Dispatcher(ICooEvent e, Vector agents) {
super(e.toString());
mAgents = agents;
mEvent = e;
start();
}
public void run() {
String curr;
while (!mAgents.isEmpty()) {
curr = mAgents.remove(0);
mEvent.setMAgentTO(curr);
try {
String hostDest = getAgentLocation(curr);
// if (hostDest.equals("localhost"))
if (!hostDest.equals("localhost"))
// TODO RIATTIVARE GUARDIA CORRETTA!!!!
// CON QUESTA GUARDIA SPEDISCO
// TRAMITE WS AGLI
// AGENTI LOCALI
CooEngine.getMAgentsManager().dispatchEvent(mEvent);
else {
Call call = createCall(hostDest);
call.invoke(new Object[] {
new CooEventRemote(mEvent, mHostname) });
}
}
catch (Exception e) {
System.out.println("[CooAgentsDirectory]"
+ "Error sending event to " + curr + ": "
+ e.getMessage());
}
}
}
/**
* Build the Call
*
* @param hostDest
*
* @return
*
* @throws ServiceException
* @throws MalformedURLException
*/
private Call createCall(String hostDest)
throws ServiceException, MalformedURLException {
Call call = (Call) new Service().createCall();
call.setTargetEndpointAddress(new URL("http://" + hostDest
+ ":4444/active-bpel/services/CooWS"));
// Registering type mapping
call.registerTypeMapping(CooDesire.class, new QName("urn:coows",
"Desire"), BeanSerializerFactory.class,
BeanDeserializerFactory.class);
call.registerTypeMapping(CooPlan.class, new QName("urn:coows",
"Plan"), BeanSerializerFactory.class,
BeanDeserializerFactory.class);
call.registerTypeMapping(CooAccessSpecifierPublic.class, new QName(
"urn:coows", "AccessSpecifierPublic"),
BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooAccessSpecifierPrivate.class,
new QName("urn:coows", "AccessSpecifierPrivate"),
BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooAccessSpecifierOnlyTrusted.class,
new QName("urn:coows", "AccessSpecifierOnlyTrusted"),
BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooSetOfPlans.class, new QName(
"urn:coows", "SetOfPlans"), BeanSerializerFactory.class,
BeanDeserializerFactory.class);
call.registerTypeMapping(CooBpelProcessBpr.class, new QName(
"urn:coows", "BpelProcessBpr"),
BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooBprFile.class, new QName("urn:coows",
"BprFile"), CooBrpFileSerializerFactory.class,
CooBprFileDeserializerFactory.class);
call.registerTypeMapping(ICooEvent.class, new QName("urn:coows",
"Event"), BeanSerializerFactory.class,
BeanDeserializerFactory.class);
call.registerTypeMapping(CooEventRequested.class, new QName(
"urn:coows", "EventRequested"),
BeanSerializerFactory.class, BeanDeserializerFactory.class);
call.registerTypeMapping(CooEventProvided.class, new QName(
"urn:coows", "EventProvided"), BeanSerializerFactory.class,
BeanDeserializerFactory.class);
call.registerTypeMapping(CooEventRemote.class, new QName(
"urn:coows", "RemoteEvent"), BeanSerializerFactory.class,
BeanDeserializerFactory.class);
call.setOperationStyle("rpc");
call.setOperationName(new QName("CooWS", "dispatchEventRemote"));
call.addParameter(REMOTEEVENT_QNAME, REMOTEEVENT_QNAME,
CooEventRemote.class, ParameterMode.IN);
return call;
}
}
}
CooWS/src/org/coows/engine/engine-id.ucd 0000664 0001750 0001750 00000056007 10171221023 021164 0 ustar joshua joshua 0000000 0000000
CooWS/src/org/coows/engine/CooRemoteDispatcher.java 0000644 0001750 0001750 00000001250 10236630216 023374 0 ustar joshua joshua 0000000 0000000 //TODO da cancellare!
package org.coows.engine;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.coows.ICooEvent;
/**
* Dispatch messages to remote hosts
*
*/
public class CooRemoteDispatcher {
private String mHostname;
public CooRemoteDispatcher() throws CooException {
try {
mHostname = InetAddress.getLocalHost().toString();
} catch (UnknownHostException e) {
throw new CooException("[CooRemoteDispatcher]"
+ " ERROR!!! Unable to get local host IP!!!");
}
}
public void dispatchEvent(String toHost, ICooEvent anEvent) {
}
public void dispatchGetProcess(String toHost, String serviceName) {
}
}
CooWS/src/org/coows/engine/CooDbConnectionsManager.java 0000664 0001750 0001750 00000002157 10232256037 024167 0 ustar joshua joshua 0000000 0000000 package org.coows.engine;
import java.sql.Connection;
import java.sql.DriverManager;
/**
* Handler for the db connections
*/
public class CooDbConnectionsManager {
/** Driver used for the connection */
private String mJdbcDriver;
/** The DB URL */
private String mCooWSDbURL;
/** The username allowed to access the mysql DB */
private String mUser;
/** The password */
private String mPwd;
public CooDbConnectionsManager(CooEngineConfiguration aConfig)
throws CooException {
mJdbcDriver = aConfig
.getText("/config/DbConnectionManagerConf/jdbcdriver");
mCooWSDbURL = aConfig.getText("/config/DbConnectionManagerConf/dburl");
mUser = aConfig.getText("/config/DbConnectionManagerConf/dbusername");
mPwd = aConfig.getText("/config/DbConnectionManagerConf/dbpassword");
}
public Connection getNewConnection() throws CooException {
try {
Class.forName(mJdbcDriver);
return DriverManager.getConnection(mCooWSDbURL, mUser, mPwd);
} catch (Exception e) {
throw new CooException(
"[CooDbConnectionsManager] Error connecting to db "
+ mCooWSDbURL + "\n" + e.getMessage());
}
}
}
CooWS/src/org/coows/engine/CooException.java 0000664 0001750 0001750 00000007021 10236630467 022104 0 ustar joshua joshua 0000000 0000000 package org.coows.engine;
/**
* Base class for all the CooWS exceptions
*/
public class CooException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
/** Flag indicating if informational logging is enabled, off by default. */
public static boolean sInfoIsOn;
/** Flag indicating if stack trace enabled, off by default. */
public static boolean sStackTraceOn = true;
/** The root cause of this exception */
protected Throwable mRootCause;
/**
* Construct a new runtime exception.
*/
public CooException() {
super();
}
/**
* Construct a new runtime exception with the passed info string.
*
* @see java.lang.Throwable#Throwable(String)
*/
public CooException(String aInfo) {
super(aInfo);
}
/**
* Construct with a root exception (used primarily for rethrowing an
* underlying exception).
*
* @param aRootCause
*/
public CooException(Throwable aRootCause) {
super(aRootCause);
setRootCause(aRootCause);
}
/**
* Construct with a root exception (used prinarily for rethrowing an
* underlying exception).
*
* @param aInfo
* Informational message for the exception
* @param aRootCause
* Root cause of the exception
*/
public CooException(String aInfo, Throwable aRootCause) {
super(aInfo, aRootCause);
setRootCause(aRootCause);
}
/**
* Sets informational logging enabled or disabled based on flag.
*
* @param aFlag
* True enables logging and False disables logging
*/
public static void setInfoOn(boolean aFlag) {
sInfoIsOn = aFlag;
}
/**
* Sets the exception which is the Root Cause of this exception.
*
* @param aRootCause
* The Root Cause to set
*/
public void setRootCause(Throwable aRootCause) {
mRootCause = aRootCause;
}
/**
* Returns the exception which is the Root Cause of this exception.
*
* @return Exception causing this exception, null if none.
*/
public Throwable getRootCause() {
return mRootCause;
}
/**
* Sets stack trace logging enabled or disabled based on flag.
*
* @param aFlag
* True enables logging and False disables stack trace logging
*/
public static void setStackTraceOn(boolean aFlag) {
sStackTraceOn = aFlag;
}
/**
* Utility method to write info to the console.
*
* @param aInfo
* Informational message to be displayed.
*/
public static void info(String aInfo) {
if (infoOn()) {
System.out.println(aInfo);
}
}
/**
* Returns true if info output is enabled.
*/
public static boolean infoOn() {
return sInfoIsOn;
}
/**
* Utility method to write info to the console.
*
* @param aPrompt
* Informational message to be displayed.
*/
public static void logError(Throwable aThrowable, String aSummary) {
System.out.println(aSummary);
if (sStackTraceOn && (aThrowable != null)) {
aThrowable.printStackTrace();
}
}
/**
* Returns true if stack trace output is enabled.
*/
public static boolean stackTraceOn() {
return sInfoIsOn;
}
/**
* Logs this exception error to the console.
*/
public void logError() {
System.out.println(getLocalizedMessage());
if (getRootCause() == null) {
if (stackTraceOn()) {
printStackTrace();
}
} else {
System.out.print("Caused by: ");
if (getRootCause() instanceof CooException) {
((CooException) getRootCause()).logError();
} else {
System.out.println(getRootCause().getLocalizedMessage());
if (stackTraceOn()) {
getRootCause().printStackTrace();
}
}
}
}
}
CooWS/src/org/coows/engine/package.html 0000644 0001750 0001750 00000000105 10204377256 021114 0 ustar joshua joshua 0000000 0000000
CooWS egine classes
CooWS/src/org/coows/engine/CooPersistenceManager.java 0000664 0001750 0001750 00000014661 10260000123 023706 0 ustar joshua joshua 0000000 0000000 package org.coows.engine;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.thoughtworks.xstream.*;
import org.coows.CooAgent;
import org.coows.CooBpelProcessBpr;
import org.coows.ICooBpelProcess;
import org.coows.util.CooAgentState;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Iterator;
/**
* Stores/Retrieves the state from the DB
*
*/
public class CooPersistenceManager {
/**
* Logger for this class
*/
private static final Log logger = LogFactory
.getLog(CooPersistenceManager.class);
/**
* Instantiates the agents from a previously saved state
* @param aConf
* @return a table of agents
* @throws CooException
*/
public static Hashtable
restoreAgents(CooEngineConfiguration aConf)
throws CooException {
if (logger.isDebugEnabled()) {
logger.debug("restoreAgents(): reloading agents state...");
}
Hashtable res = new Hashtable();
XStream xstream = new XStream();
Statement st;
ResultSet rs;
Connection dbConn;
CooAgentState currAgentState;
CooAgent currAgent;
// debug("Getting connection to the db....");
dbConn = (new CooDbConnectionsManager(aConf)).getNewConnection();
try {
st = dbConn.createStatement();
// debug("Querying for agents states...");
rs = st.executeQuery("SELECT * FROM agentsXML");
if (logger.isDebugEnabled()) {
logger.debug("restoreAgents() - " +
"agents states retrieved! Now initialiazing!");
}
while (rs.next()) {
//logger.debug("yahooooooooooooooooooooooooooooooooooo");
currAgentState = (CooAgentState)
xstream.fromXML(rs.getString("serializedagent"));
//logger.debug("yahiiiiiiiiiiiiiiiiii");
currAgent = new CooAgent(currAgentState);
//logger.debug("yahiaaaaaaaaaaaaaaaai");
res.put(currAgent.getMAgentID(), currAgent);
}
dbConn.close();
if (logger.isDebugEnabled()) {
logger.debug("restoreAgents() - Agents state initialized!");
}
} catch (SQLException e) {
throw new CooException(
"[CooPersistenceManager] Error while deserializing agents"
+ " from the db!\n" + e.getMessage());
}
if (logger.isDebugEnabled())
{
logger.debug("restoreAgents() - Agents states reloaded!");
}
return res;
}
/**
* Retrieve the BPEL processes saved to the db
* @param aConf
* @return
* @throws CooException
*/
public static Hashtable
restoreBpelProcesses(CooEngineConfiguration aConf)
throws CooException {
Hashtable res =
new Hashtable();
XStream xstream = new XStream();
Statement st;
ResultSet rs;
Connection dbConn;
ICooBpelProcess currProcess;
dbConn = (new CooDbConnectionsManager(aConf)).getNewConnection();
try {
st = dbConn.createStatement();
rs = st.executeQuery("SELECT * FROM bpelProcessesXML");
while (rs.next()) {
currProcess = (CooBpelProcessBpr) xstream.fromXML(
rs.getString("serializedBpelProcess"));
res.put(currProcess.getServiceName(), currProcess);
System.out.println("[CooPersistenceManager] Process "
+ currProcess.getServiceName() + " retrieved.");
}
dbConn.close();
} catch (SQLException e) {
throw new CooException("[CooPersistenceManager]" +
"Error while deserializing agents " +
"from the db!\n" + e.getMessage());
}
return res;
}
/**
*
* @param aConf
* @param agents
* @throws CooException
*/
public static void serializeAgents(
CooEngineConfiguration aConf,
Collection agents)
throws CooException {
Statement st;
PreparedStatement pSt;
ResultSet rs;
CooAgentState currAgentState;
String agent2xml;
XStream xstream = new XStream();
Connection dbConn = (new CooDbConnectionsManager(aConf))
.getNewConnection();
try {
st = dbConn.createStatement();
st.execute("DELETE FROM agentsXML WHERE 1");
st.close();
pSt = dbConn.prepareStatement("INSERT INTO agentsXML VALUES (?)");
//for (CooAgentState as : agents) {}
for (Iterator i = agents.iterator(); i.hasNext();) {
currAgentState = ((CooAgent) i.next()).getAgentState();
agent2xml = xstream.toXML(currAgentState);
// debug("AGENT " + currAgent.getMAgentID()
// + " SERIALIZED:\n" + agent2xml);
// pSt.setString(1, currAgent.getMAgentID());
pSt.setString(1, agent2xml);
pSt.executeUpdate();
}
if (logger.isDebugEnabled())
{
logger.debug("serializeAgents() done!");
}
pSt.close();
dbConn.close();
} catch (SQLException e) {
throw new CooException(
"[CooPersistenceManager] Error while serializing agents"
+ "to the db!\n" + e.getMessage());
}
}
/**
*
* @param aConf
* @param processes
* @throws CooException
*/
public static void serializeProcesses(CooEngineConfiguration aConf,
Collection processes) throws CooException {
Statement st;
PreparedStatement pSt;
ResultSet rs;
CooBpelProcessBpr currProcess;
String process2xml;
XStream xstream = new XStream();
Connection dbConn = (new CooDbConnectionsManager(aConf))
.getNewConnection();
try {
st = dbConn.createStatement();
st.execute("DELETE FROM bpelProcessesXML WHERE 1");
st.close();
pSt = dbConn.prepareStatement(
"INSERT INTO bpelProcessesXML VALUES (?,?)");
for (Iterator i = processes.iterator(); i.hasNext();) {
currProcess = (CooBpelProcessBpr) i.next();
process2xml = xstream.toXML(currProcess);
pSt.setString(1, currProcess.getServiceName());
pSt.setString(2, process2xml);
pSt.executeUpdate();
}
dbConn.close();
if (logger.isDebugEnabled())
{
logger.debug("serializeProcesses() done!");
}
} catch (SQLException e) {
throw new CooException(
"[CooPersistentManager] Error while serializing processes"
+ "to the db!\n" + e.getMessage());
}
}
}
CooWS/src/org/coows/CooAccessSpecifierOnlyTrusted.java 0000664 0001750 0001750 00000002065 10260242352 024141 0 ustar joshua joshua 0000000 0000000 package org.coows;
import java.util.Vector;
/**
* Class for ONLY_TRUSTED access specifier type
*/
public class CooAccessSpecifierOnlyTrusted
extends CooAbstractAccessSpecifier {
/** Agents with grant access to the plan */
public Vector mTrustedAgents;
/** Constructor */
public CooAccessSpecifierOnlyTrusted() {
super("ONLY_TRUSTED");
this.mTrustedAgents = new Vector();
}
/**
* Constructor
*
* @param aAccSpec a list of agents ID to grant
*/
public CooAccessSpecifierOnlyTrusted(Vector aTrustedAgentsList) {
super("ONLY_TRUSTED");
this.mTrustedAgents = aTrustedAgentsList;
}
/**
* Update the set of trusted agents with a new agent
*
* @param anAgentID the agent to trust
*/
public void trustAgent(String anAgentID) {
if (!mTrustedAgents.contains(anAgentID))
mTrustedAgents.add(anAgentID);
}
/**
* @see ICooAccessSpecifier#isTrusted(java.lang.String)
*/
public boolean isTrusted(String anAgentID) {
if (mTrustedAgents.contains(anAgentID))
return true;
else
return false;
}
}
CooWS/src/org/coows/CooGlobalEventsQueue.java 0000644 0001750 0001750 00000005073 10260025406 022262 0 ustar joshua joshua 0000000 0000000 package org.coows;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.LinkedList;
import org.apache.commons.pool.impl.GenericObjectPool;
import org.coows.engine.CooEngine;
import org.coows.engine.CooException;
import org.coows.work.CooWorkerDispatcher;
import org.coows.work.CooWorkerDispatcherFactory;
public class CooGlobalEventsQueue {
/**
* Logger for this class
*/
private static final Log logger = LogFactory
.getLog(CooGlobalEventsQueue.class);
/**
* The list of queued event waiting to be dispatched
*/
private LinkedList mQueuedEvents;
/**
* The number of max active workers allowed
*/
private int mMaxActiveWorkers;
/**
* The pool of threads
*/
private GenericObjectPool mDispatchersPool;
/**
* Constructor
* @throws CooException
*/
public CooGlobalEventsQueue()
throws CooException {
try {
mDispatchersPool = new GenericObjectPool(
new CooWorkerDispatcherFactory());
mMaxActiveWorkers = Integer.parseInt(CooEngine.getMConfig()
.getText("/config/pools/globalDispatchers/maxActive"));
mDispatchersPool.setMaxActive(mMaxActiveWorkers);
mQueuedEvents = new LinkedList();
} catch(Exception e) {
throw new CooException("Error initializing EventQueue!");
}
}
/**
* Enqueue the event
* @param anEvent
*/
public void enqueue(ICooEvent anEvent) {
try {
if (mMaxActiveWorkers > mDispatchersPool.getNumActive()) {
CooWorkerDispatcher w = (CooWorkerDispatcher)
mDispatchersPool.borrowObject();
w.setPool(mDispatchersPool);
w.dispatchEvent(
CooEngine.getMAgentsManager().getAgent(anEvent.getMAgentTO()),
anEvent);
}
else {
synchronized (mQueuedEvents) {
mQueuedEvents.add(anEvent);
}
}
}
catch (Exception e) {
if (logger.isErrorEnabled()) {
logger.error("enqueue() - Error while dispatching event "
+ anEvent, e);
}
}
}
/**
*
* @uml.property name="mQueuedEvents"
*/
public LinkedList getMQueuedEvents() {
return mQueuedEvents;
}
public void clear() {
mQueuedEvents.clear();
}
}
CooWS/src/org/coows/CooEventAchieve.java 0000644 0001750 0001750 00000003012 10257017150 021230 0 ustar joshua joshua 0000000 0000000 package org.coows;
/**
* This event carries the info for the "achieve" op
*/
public class CooEventAchieve
extends CooAbstractEvent {
/**
* The desire to achieve
*
* @uml.property name="mDes"
* @uml.associationEnd multiplicity="(0 1)"
*/
private ICooDesire mDes;
/**
* The intention ID wich belongs the plan
* that generate this event
*/
private String mIntentionID;
/**
* Constructor
* @param anAgentTO
* @param anIntentionID
* @param aDes
*/
public CooEventAchieve(
String anAgentTO,
String anIntentionID,
String aDes) {
mAgentTO = anAgentTO;
mIntentionID = anIntentionID;
mDes = new CooDesire(aDes);
}
/**
*
* @uml.property name="mDes"
*/
public ICooDesire getMDes() {
return mDes;
}
/**
*
* @uml.property name="mDes"
*/
public void setMDes(ICooDesire des) {
mDes = des;
}
/**
* @see org.coows.ICooEvent#dd(org.coows.CooAgent)
*/
public void dd(CooAgent anAgent) {
anAgent.onEventAchieve(this);
}
/**
*
* @uml.property name="mIntentionID"
*/
public String getMIntentionID() {
return mIntentionID;
}
/**
*
* @uml.property name="mIntentionID"
*/
public void setMIntentionID(String intentionID) {
mIntentionID = intentionID;
}
public String toString() {
return "EventAchieve("+mAgentTO+","+mIntentionID+","+mDes+")";
}
}
CooWS/src/org/coows/CooBpelProcessBpr.java 0000664 0001750 0001750 00000006650 10261250014 021555 0 ustar joshua joshua 0000000 0000000 package org.coows;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.coows.engine.CooEngine;
import org.coows.engine.CooException;
import org.coows.util.CooBprFile;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.encoding.XMLType;
/**
* Class container for a binary .bpr file
*/
public class CooBpelProcessBpr
implements ICooBpelProcess {
/**
* The binary content of the .bpr file
*
* @uml.property name="mBprFile"
* @uml.associationEnd multiplicity="(0 1)"
*/
private CooBprFile mBprFile;
/** The service name of the process contained into the .bpr file */
private String mServiceName;
/**
* Constructor
*
*/
public CooBpelProcessBpr() {
}
/**
* Constructor
*
* @param aBprFile
* @param aServiceName
*/
public CooBpelProcessBpr(CooBprFile aBprFile, String aServiceName) {
this.mBprFile = aBprFile;
this.mServiceName = aServiceName;
}
public void setBprFile(CooBprFile aBprFile) {
this.mBprFile = aBprFile;
}
public CooBprFile getBprFile() {
return mBprFile;
}
public void setServiceName(String aServiceName) {
this.mServiceName = aServiceName;
}
public String getServiceName() {
return mServiceName;
}
/**
* Deploys the process to the ActiveBPEL engine
*
* @throws CooException
*/
public void deploy() throws CooException {
String bprDir = CooEngine.CATALINA_HOME + "/bpr";
try {
// Deploy == Crete che .bpr file into the bpr directory
FileOutputStream fos = new FileOutputStream(bprDir + "/"
+ mServiceName + ".bpr");
byte[] contentFile = new byte[mBprFile.getBin().available()];
mBprFile.getBin().read(contentFile);
fos.write(contentFile);
fos.close();
} catch (FileNotFoundException e) {
throw new CooException(" Unable to deploy process " + mServiceName
+ "\n" + e.getMessage());
} catch (IOException e) {
throw new CooException(" Unable to deploy process " + mServiceName
+ "\n" + e.getMessage());
}
}
/**
* @throws CooException
* @see org.coows.ICooBpelProcess#invoke(org.coows.CooBpelProcessParameters)
*/
public void invoke(CooBpelProcessParameters p) throws CooException {
Call call;
try {
call = createInvokeCall(p);
call.invoke(new Object[] { p.getAgentInvoker() });
} catch (Exception e) {
throw new CooException("[CooBpelProcessBpr]"
+ " Error invoking bpel process " + mServiceName + "\n"
+ e.getLocalizedMessage());
}
}
public Call createInvokeCall(CooBpelProcessParameters params)
throws ServiceException, MalformedURLException {
Call call = (Call) new Service().createCall();
call.setTargetEndpointAddress(new URL(
"http://localhost:8080/active-bpel/services/" + mServiceName));
call.setOperationName("runPlanOp");
// Registering type mapping
// call.registerTypeMapping(CooDesire.class,
// new QName("urn:coows", "Desire"),
// BeanSerializerFactory.class, BeanDeserializerFactory.class);
// Adding parameters to call
call.addParameter("agentID", XMLType.XSD_STRING, ParameterMode.IN);
// call.setOperationStyle("rpc");
// call.setOperationName();
return call;
}
/**
*
* @see org.coows.ICooBpelProcess#undeploy()
*/
public void undeploy() {
//TODO
}
}
CooWS/src/org/coows/ICooEvent.java 0000644 0001750 0001750 00000000751 10257017147 020071 0 ustar joshua joshua 0000000 0000000 package org.coows;
import org.coows.work.ICooWorkItem;
/**
* The events interface
*/
public interface ICooEvent extends ICooWorkItem {
/** Double dispatch the event*/
public void dd(CooAgent anAgent);
/**
* Modifier for the agentTO field
*
* @uml.property name="mAgentTO"
*/
public String getMAgentTO();
/**
* Modifier for the agentTO field
*
* @uml.property name="mAgentTO"
*/
public void setMAgentTO(String mAgentID);
}
CooWS/src/org/coows/CooBpelProcessParameters.java 0000644 0001750 0001750 00000002051 10243716030 023127 0 ustar joshua joshua 0000000 0000000 package org.coows;
/**
* Parameters used to invoke a process
*/
public class CooBpelProcessParameters {
/**
* May be useful when using remote BPEL engines
*/
private String mHostInvoker;
/**
* The agent "owner"
*/
private String mAgentInvoker;
/**
* The intention that started the call
*/
private String mIntentionID;
/**
* Constructor
*/
public CooBpelProcessParameters() {
}
/**
* Constructor
* @param agent
* @param host
*/
public CooBpelProcessParameters(
String anHost,
String anAgent,
String anIntentionID) {
this.mHostInvoker = anHost;
this.mAgentInvoker = anAgent;
this.mIntentionID = anIntentionID;
}
public void setAgentInvoker(String agentInvoker) {
this.mAgentInvoker = agentInvoker;
}
public String getAgentInvoker() {
return mAgentInvoker;
}
public void setHostInvoker(String hostInvoker) {
this.mHostInvoker = hostInvoker;
}
public String getHostInvoker() {
return mHostInvoker;
}
}
CooWS/src/org/coows/CooInstanceRecord.java 0000644 0001750 0001750 00000006746 10260267734 021617 0 ustar joshua joshua 0000000 0000000 package org.coows;
import java.util.Calendar;
import java.util.Vector;
import org.coows.engine.CooEngine;
import org.coows.util.CooSetOfPlans;
public class CooInstanceRecord {
/**
* Boolean flag for
*/
public Boolean mIsSuspended;
/**
*
* @uml.property name="mCurrentRunningPlan"
* @uml.associationEnd multiplicity="(0 1)"
*/
public CooPlan mCurrentRunningPlan;
/**
*
* @uml.property name="mRelevantPlans"
* @uml.associationEnd multiplicity="(0 1)"
*/
public Vector mRelevantPlans;
/**
*
* @uml.property name="mFailedPlans"
* @uml.associationEnd multiplicity="(0 1)"
*/
public Vector mFailedPlans;
/**
*
* @uml.property name="mDes"
* @uml.associationEnd multiplicity="(0 1)"
*/
private ICooDesire mDes;
private Calendar mTimeout;
/**
*
* @uml.property name="mRefToPrev"
* @uml.associationEnd multiplicity="(0 1)"
*/
private CooInstanceRecord mRefToPrev;
/**
*
* @uml.property name="mRefToIntention"
* @uml.associationEnd multiplicity="(0 1)"
*/
private CooIntention mRefToIntention;
/**
* Constructor
* @param aDes
* @param aSop
*/
public CooInstanceRecord(ICooDesire aDes, CooSetOfPlans aSop) {
mDes = aDes;
mRelevantPlans = new Vector(aSop.getCollection());
mFailedPlans = new Vector();
mTimeout = Calendar.getInstance();
mTimeout.add(Calendar.SECOND, 20);
if (mRelevantPlans.isEmpty())
mIsSuspended = Boolean.TRUE;
else
mIsSuspended = Boolean.FALSE;
}
/**
* Receive a set of provided plans
* @param aSop
*/
public void provided(CooSetOfPlans aSop) {
Vector prov = new Vector(aSop.getCollection());
prov.remove(mCurrentRunningPlan);
prov.removeAll(mFailedPlans);
if (prov.isEmpty())
return;
synchronized (mIsSuspended) {
mRelevantPlans.addAll(prov);
if (mIsSuspended.booleanValue()) {
mIsSuspended = Boolean.FALSE;
runNextPlan();
}
}
}
public boolean isInTimeout() {
return Calendar.getInstance().after(mTimeout);
}
public void fail() {
if (mRefToPrev == null)
mRefToIntention.fail();
else
mRefToPrev.failCurrentPlan();
}
public void failCurrentPlan() {
mFailedPlans.add(mCurrentRunningPlan);
mCurrentRunningPlan = null;
if (!mRelevantPlans.isEmpty()) {
runNextPlan();
} else
if (isInTimeout())
this.fail();
else
mIsSuspended = Boolean.FALSE;
}
/**
*
* @uml.property name="mRefToPrev"
*/
public void setMRefToPrev(CooInstanceRecord refToPrev) {
mRefToPrev = refToPrev;
}
/**
*
* @uml.property name="mRefToIntention"
*/
public void setMRefToIntention(CooIntention refToIntention) {
mRefToIntention = refToIntention;
}
public void runNextPlan() {
mCurrentRunningPlan = mRelevantPlans.remove(0);
CooEngine.getMProcessesManager().invokeProcess(
mRefToIntention.getMAgentOwner(),
mRefToIntention.getMIntentionID(),
mCurrentRunningPlan.getMPlanID());
}
}
CooWS/src/org/coows/CooAgent.java 0000664 0001750 0001750 00000027512 10264514406 017741 0 ustar joshua joshua 0000000 0000000 package org.coows;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.coows.engine.CooEngine;
import org.coows.engine.CooException;
import org.coows.util.CooAgentState;
import org.coows.util.CooRequestID;
import org.coows.util.CooSetOfIntention;
import org.coows.util.CooSetOfPlans;
import java.util.Calendar;
import java.util.Vector;
/**
* The CooWS agent
*/
public class CooAgent
extends Thread {
/**
* Logger for this class
*/
private static final Log logger = LogFactory.getLog(CooAgent.class);
/* Retrieval strategy constants */
public static final int RETRIEVAL_STRATEGY_ALWAYS = 0;
public static final int RETRIEVAL_STRATEGY_NOLOCAL = 1;
/* Acquisition strategy constants */
public static final int ACQUISITION_STRATEGY_ADD = 0;
public static final int ACQUISITION_STRATEGY_REPLACE = 1;
public static final int ACQUISITION_STRATEGY_DISCARD = 2;
/**
* The agent ID
*/
private String mAgentID;
/**
* The list of known agents
*/
private Vector mPartners;
/**
* The agent plan library
*
* @uml.property name="mPlans"
* @uml.associationEnd multiplicity="(0 1)"
*/
private CooSetOfPlans mPlans;
/**
* The acquisition strategy.
* Values range within the following values:
* CooAgent.ACQUSITION_STRATEGY_ADD
* CooAgent.ACQUISITION_STRATEGY_REPLACE
* CooAgent.ACQUISITION_STRATEGY_DISCARD
*/
private int mAcquisitionStrategy;
/**
* The retrieval strategy.
* Values range within the following values:
* CooAgent.RETRIEVAL_STRATEGY_ALWAYS
* CooAgent.RETRIEVAL_STRATEGY_NOLOCAL
*/
private int mRetrievalStrategy;
/**
* The intentions table
* For each intention ID a CooIntention is
*
* @uml.property name="mIntentions"
* @uml.associationEnd multiplicity="(0 1)"
*/
private CooSetOfIntention mIntentions;
/**
* The agent's event queue
*
* @uml.property name="mEventQueue"
* @uml.associationEnd multiplicity="(0 1)"
*/
private CooAgentEventsQueue mEventQueue;
private boolean mPrepare4shutdown;
private boolean mShutdown;
/**
* Constructor
*
* @param anAgentState
* A previously serialized agent state
* @throws CooException
*/
public CooAgent(CooAgentState anAgentState)
throws CooException {
init();
mAgentID = anAgentState.getMAgentID();
mPlans = anAgentState.getMSop();
mPartners = anAgentState.getMPartners();
mAcquisitionStrategy = anAgentState.getMAcquisitionStrategy();
mRetrievalStrategy = anAgentState.getMRetrievalStrategy();
if (logger.isDebugEnabled()) {
logger.debug("CooAgent() - agent " + mAgentID + " created");
}
}
/**
* Auxiliary constructor (for debug and test)
*
* @param anAgentID
* @param anAcquisitionSTRATEGY
* @param aSop
* @throws CooException
*/
public CooAgent(
String anAgentID, int anAcquisitionStrategy, CooSetOfPlans aSop)
throws CooException {
init();
mAgentID = anAgentID;
mAcquisitionStrategy = anAcquisitionStrategy;
mPlans = aSop;
if (logger.isDebugEnabled()) {
logger.debug("CooAgent() - agent " + mAgentID + " created");
}
}
/**
* Init the local data structures (event queue, workers pool and boolean
* variables)
*
* @throws CooException
*/
public void init()
throws CooException {
//mEventQueueOLD = new LinkedList();
mEventQueue = new CooAgentEventsQueue(this);
//mWorkers = new GenericObjectPool(new CooWorkerProcessEventFactory());
//mMaxActiveWorkers = Integer.parseInt(CooEngine.getMConfig().getText(
// "/config/pools/agentWorkers/maxActive"));
//mWorkers.setMaxActive(mMaxActiveWorkers);
mPrepare4shutdown = false;
mShutdown = false;
}
/**
* Process new incoming events (assigns the work to a new thread or enqueue
* locally)
*
* @param anEvent
*/
public void onEvent(ICooEvent anEvent) {
if (logger.isDebugEnabled()) {
logger.debug("agent: " + mAgentID + ", " + "onEvent(anEvent = "
+ anEvent + ")");
}
// if we are going to shutdown
if (true == mPrepare4shutdown)
// discharge all events
return;
mEventQueue.enqueue(anEvent);
}
/**
* Callback for "achieve" requests
*
* @param anEvent
*/
public void onEventAchieve(CooEventAchieve anEvent) {
if (logger.isDebugEnabled()) {
logger.debug("Agent: " + mAgentID
+ "onEventAchieve(" + anEvent + ")");
}
CooSetOfPlans relPlans = mPlans.getRelevant(anEvent.getMDes());
CooInstanceRecord instRec =
new CooInstanceRecord(anEvent.getMDes(), relPlans);
try {
CooIntention theInt;
theInt = mIntentions.getIntention(anEvent.getMIntentionID());
String instID = theInt.push(instRec);
// TODO lanciare in esecuzione un piano se relplans NON vuoto
if ((RETRIEVAL_STRATEGY_ALWAYS == mRetrievalStrategy)
|| ((RETRIEVAL_STRATEGY_NOLOCAL == mRetrievalStrategy)
&& relPlans.isEmpty()))
sendRequested(
anEvent.getMDes(), anEvent.getMIntentionID(), instID);
}
catch (CooException e) {
if (logger.isErrorEnabled()) {
logger.error("Agent "+ mAgentID +" encountered an exception " +
"processing an message for intention " +
anEvent.getMIntentionID(),e);
}
}
}
public void onEventOrdinary(CooEventOrdinary anEvent) {
String intID =
String.valueOf(Calendar.getInstance().getTimeInMillis());
// Create a new intention
CooIntention newInt = new CooIntention(mAgentID, intID,
anEvent.getMSuccessAction(), anEvent.getMFailureAction());
// Retrieve relevant plans
CooSetOfPlans relPlans = mPlans.getRelevant(anEvent.getMDesire());
// Create the first instance record for the intention stack
CooInstanceRecord instRec =
new CooInstanceRecord(anEvent.getMDesire(), relPlans);
// Push the record on the stack
newInt.push(instRec);
// Update the intentions set
mIntentions.addIntention(newInt);
// If available, run the first relevant plan
if (!relPlans.isEmpty())
instRec.runNextPlan();
// Send requested
if ((mRetrievalStrategy == RETRIEVAL_STRATEGY_ALWAYS)
|| ((mRetrievalStrategy == RETRIEVAL_STRATEGY_NOLOCAL)
&& (relPlans.isEmpty())))
sendRequested(anEvent.getMDesire(), intID, "0");
}
public void onEventPlanOutcome(CooEventPlanOutcome anEvent) {
try {
CooIntention anInt =
mIntentions.getIntention(anEvent.getMIntentionID());
anInt.dispatchPlanOutcome(anEvent);
}
catch (CooException e) {
if (logger.isErrorEnabled()) {
logger.error("Agent " + mAgentID + " encountered an exception" +
" processing a message for intention" +
anEvent.getMIntentionID(), e);
}
}
}
/**
* Callback for incoming "provided" events
*
* @param anEvent
*/
public void onEventProvided(CooEventProvided anEvent) {
if (logger.isDebugEnabled()) {
logger.debug("onEventProvided() - Agent " + mAgentID +
": Processing " + anEvent);
}
if (mAcquisitionStrategy == ACQUISITION_STRATEGY_ADD) {
mPlans.addPlans(anEvent.getMProvidedPlans());
} else if (mAcquisitionStrategy == ACQUISITION_STRATEGY_REPLACE)
mPlans.replace(anEvent.getMProvidedPlans());
else if (mAcquisitionStrategy == ACQUISITION_STRATEGY_DISCARD)
; // nothing to do
else
if (logger.isErrorEnabled()) {
logger.error("onEventProvided() - Agent " + mAgentID +
"has an unknown acquisition policy!", null);
}
try {
CooIntention anInt =
mIntentions.getIntention(anEvent.getMReqID().getMIntentionID());
anInt.dispatchProvided(anEvent);
}
catch (CooException e) {
if (logger.isErrorEnabled()) {
logger.error("Agent " + mAgentID + " encountered an exception" +
" processing a message for intention" +
anEvent.getMReqID().getMIntentionID(), e);
}
}
// TODO update the intention stack
}
/**
* Callback for incoming "requested" events
*
* @param anEvent
*/
public void onEventRequested(CooEventRequested anEvent) {
if (logger.isDebugEnabled()) {
logger.debug("onEventRequested() - Agent " + mAgentID +
": Processing " + anEvent);
}
CooSetOfPlans res = mPlans.getRelevantForAgent(anEvent.getMAgentFROM(),
anEvent.getMDes());
if (res.isEmpty()) {
if (logger.isDebugEnabled()) {
logger.debug("onEventRequested() - no relevant plans " +
"found for " + anEvent.getMDes());
}
return;
}
else {
// let's build the reply event...
CooEventProvided evt = new CooEventProvided(mAgentID, anEvent
.getMAgentFROM(), anEvent.getMReqID(), res);
// ... and send it!
CooEngine.getAgentsDirectory().sendEvent(evt);
}
}
public void prepare4shutdown() {
this.mPrepare4shutdown = true;
}
public void run() {
while (!mPrepare4shutdown) {
try {
sleep(5000);
}
catch (InterruptedException e) {}
}
//TODO Gestire intenzioni in esecuzione
while (!mShutdown) {
}
// TODO
if (logger.isDebugEnabled()) {
logger.debug("Agent " + mAgentID + " stopped!");
}
}
public void shutdown() {
this.mShutdown = true;
}
/**
* Creates and returns a snapshot of the agent state
*
* @return
*/
public CooAgentState getAgentState() {
return new CooAgentState(mAgentID, mPlans, mPartners,
mRetrievalStrategy, mAcquisitionStrategy);
}
/**
*
* @uml.property name="mEventQueue"
*/
public CooAgentEventsQueue getMEventQueue() {
return mEventQueue;
}
/**
*
* @uml.property name="mAgentID"
*/
public String getMAgentID() {
return mAgentID;
}
/**
* Construct and send a "requested" event to the set of partner agents
*
* @param aDes
* The desire
* @param intD
* The intention source of the request
* @param stackPos
* The position inside the intention stack of the
* @param instanceID
* The id of the instance record
*/
private void sendRequested(
ICooDesire aDes,
String intID,
String instanceID) {
CooEventRequested aReq = new CooEventRequested(mAgentID, "",
new CooRequestID(intID, instanceID), aDes);
CooEngine.getAgentsDirectory().sendEvent(aReq, mPartners);
}
} CooWS/src/org/coows/CooAbstractAccessSpecifier.java 0000664 0001750 0001750 00000001422 10257017153 023411 0 ustar joshua joshua 0000000 0000000 package org.coows;
/**
* Base class for the Access Specifier implementations
*/
abstract public class CooAbstractAccessSpecifier
implements ICooAccessSpecifier {
/** Constant: one value among {"PRIVATE", "PUBLIC", "ONLY_TRUSTED"} */
private final String mAccessSpecifier;
/**
* Constructor
*
* @param aAccSpec
*/
public CooAbstractAccessSpecifier(String aAccSpec) {
mAccessSpecifier = aAccSpec;
}
/**
* Modifier
* @return may be "PUBLIC" OR "PRIVATE" OR "ONLY_TRUSTED"
*
* @uml.property name="mAccessSpecifier"
*/
public String getMAccessSpecifier() {
return mAccessSpecifier;
}
/**
* Check if an agent is trusted
* @param anAgentID
* @return
*/
public abstract boolean isTrusted(String anAgentID);
}
CooWS/src/org/coows/CooDesire.java 0000664 0001750 0001750 00000001620 10257017151 020103 0 ustar joshua joshua 0000000 0000000 package org.coows;
import org.coows.ICooDesire;
/**
* A simple desire implementation
*/
public class CooDesire
implements ICooDesire {
/**
* A desire is a string
*/
private String mDes;
/**
* Constructor
*
*/
public CooDesire() {
}
/**
* Constructor
*/
public CooDesire(String aDes) {
this.mDes = aDes;
}
public String toString() {
return "Desire("+mDes+")";
}
/**
*
* @see org.coows.ICooDesire#match(org.coows.ICooDesire)
*/
public boolean match(ICooDesire aDes) {
if (aDes instanceof CooDesire)
return mDes.equals(((CooDesire)aDes).getMDes());
else
return false;
}
/**
*
* @uml.property name="mDes"
*/
public String getMDes() {
return mDes;
}
/**
*
* @uml.property name="mDes"
*/
public void setMDes(String des) {
mDes = des;
}
}
CooWS/src/org/coows/CooAgentEventsQueue.java 0000644 0001750 0001750 00000005126 10260242424 022120 0 ustar joshua joshua 0000000 0000000 package org.coows;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.LinkedList;
import org.apache.commons.pool.impl.GenericObjectPool;
import org.coows.engine.CooEngine;
import org.coows.engine.CooException;
import org.coows.work.CooWorkerProcessEvent;
import org.coows.work.CooWorkerProcessEventFactory;
public class CooAgentEventsQueue {
/**
* Logger for this class
*/
private static final Log logger =
LogFactory.getLog(CooAgentEventsQueue.class);
private LinkedList mQueuedEvents;
private int mMaxActiveWorkers;
private GenericObjectPool mWorkersPool;
/**
*
* @uml.property name="mAgentOwner"
* @uml.associationEnd multiplicity="(0 1)"
*/
private CooAgent mAgentOwner;
/**
* The pool of thread worker
*/
private GenericObjectPool mDispatchersPool;
public CooAgentEventsQueue(CooAgent anAgent)
throws CooException {
try {
mWorkersPool = new GenericObjectPool(
new CooWorkerProcessEventFactory());
mMaxActiveWorkers = Integer.parseInt(CooEngine.getMConfig()
.getText("/config/pools/agentWorkers/maxActive"));
mWorkersPool.setMaxActive(mMaxActiveWorkers);
mAgentOwner = anAgent;
mQueuedEvents = new LinkedList();
} catch(Exception e) {
throw new CooException("Error initializing EventQueue!");
}
}
public void enqueue(ICooEvent anEvent) {
try {
if (mMaxActiveWorkers > mWorkersPool.getNumActive()) {
// process immediatly the new event
CooWorkerProcessEvent w = (CooWorkerProcessEvent)
mWorkersPool.borrowObject();
w.setPool(mWorkersPool);
w.processEvent(mAgentOwner, anEvent);
}
else {
// enqueue the event
synchronized (mQueuedEvents) {
mQueuedEvents.add(anEvent);
}
if (logger.isDebugEnabled()) {
logger.debug("enqueue() - Event " + anEvent +"enqueued!");
}
}
} catch (Exception e) {
if (logger.isErrorEnabled())
logger.error("agent: " + mAgentOwner
+"onEvent(ICooEvent) error processing " + anEvent, e);
}
}
/**
*
* @uml.property name="mQueuedEvents"
*/
public LinkedList getMQueuedEvents() {
return mQueuedEvents;
}
}
CooWS/src/org/coows/coows-id.ucd 0000664 0001750 0001750 00000117300 10171221761 017607 0 ustar joshua joshua 0000000 0000000
CooWS/src/org/coows/ICooAccessSpecifier.java 0000644 0001750 0001750 00000000404 10236360062 022030 0 ustar joshua joshua 0000000 0000000 package org.coows;
/**
* Define the interface for the
* Access Specifier implementation
*/
public interface ICooAccessSpecifier {
/**
* Checks if an agent is trusted
* @param anAgentID
* @return
*/
public boolean isTrusted(String anAgentID);
}
CooWS/src/org/coows/CooEventRequested.java 0000664 0001750 0001750 00000003623 10257017147 021645 0 ustar joshua joshua 0000000 0000000 package org.coows;
import org.coows.util.CooRequestID;
/**
* Wrapper for data used by requested op
*/
public class CooEventRequested
extends CooAbstractEvent {
/**
* The requestor ID
*/
private String mAgentFROM;
/**
* The request ID
*
* @uml.property name="mReqID"
* @uml.associationEnd multiplicity="(0 1)"
*/
private CooRequestID mReqID;
/**
* The desire
*
* @uml.property name="mDes"
* @uml.associationEnd multiplicity="(0 1)"
*/
private ICooDesire mDes;
/**
* Constructor
*
*/
public CooEventRequested() {
mAgentTO = "";
mAgentFROM = "";
mReqID = null;
mDes = new CooDesire();
}
/**
* Constructor
*
* @param anAgentID
* @param aDes
*/
public CooEventRequested(String anAgentFROM, String anAgentTO,
CooRequestID aReqID, ICooDesire aDes) {
mAgentFROM = anAgentFROM;
mAgentTO = anAgentTO;
mReqID = aReqID;
mDes = aDes;
}
/**
*
* @uml.property name="mAgentFROM"
*/
public String getMAgentFROM() {
return mAgentFROM;
}
/**
*
* @uml.property name="mAgentFROM"
*/
public void setMAgentFROM(String agentID) {
mAgentFROM = agentID;
}
/**
*
* @uml.property name="mDes"
*/
public ICooDesire getMDes() {
return mDes;
}
public void setMDes(CooDesire des) {
mDes = des;
}
/**
*
* @uml.property name="mReqID"
*/
public CooRequestID getMReqID() {
return mReqID;
}
/**
*
* @uml.property name="mReqID"
*/
public void setMReqID(CooRequestID reqID) {
mReqID = reqID;
}
public String toString() {
return "EventRequested("+mAgentFROM+","
+mAgentTO+","+mReqID+","+mDes+")";
}
/**
* @see org.coows.ICooEvent#dd(org.coows.CooAgent)
*/
public void dd(CooAgent anAgent) {
anAgent.onEventRequested(this);
}
}
CooWS/src/org/coows/CooEventPlanOutcome.java 0000644 0001750 0001750 00000002062 10257017152 022120 0 ustar joshua joshua 0000000 0000000 package org.coows;
/**
* The event for the dispatch of plan outcome
*/
public class CooEventPlanOutcome
extends CooAbstractEvent {
/** The intention ID wich belongs the completed plan */
private String mIntentionID;
/** The outcome: TRUE (successfully completed) or FALSE (failed) */
private boolean mOutcome;
/**
* Constructor
* @param anAgentTO
* @param anIntentionID
* @param anOutcome
*/
public CooEventPlanOutcome(String anAgentTO, String anIntentionID,
boolean anOutcome) {
mAgentTO = anAgentTO;
mIntentionID = anIntentionID;
mOutcome = anOutcome;
}
/**
*
* @uml.property name="mIntentionID"
*/
public String getMIntentionID() {
return mIntentionID;
}
public boolean isSuccess() {
return mOutcome;
}
/**
* @see org.coows.ICooEvent#dd(org.coows.CooAgent)
*/
public void dd(CooAgent anAgent) {
anAgent.onEventPlanOutcome(this);
}
public String toString() {
return "EventPlanOutcome("+mAgentTO+","+mIntentionID+","+mOutcome+")";
}
}
CooWS/src/org/coows/CooEventFIPAACLMessage.java 0000644 0001750 0001750 00000001427 10247337357 022255 0 ustar joshua joshua 0000000 0000000 package org.coows;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class CooEventFIPAACLMessage
extends CooAbstractEvent {
/**
* The FIPA ACL Message adapted
*/
//TODO importare la classe/libreria dall'implementazione di FIPA
// Aggiornare il .wsdd con il beanSerializer opportuno!!!!!!
/**
* Logger for this class
*/
private static final Log logger =
LogFactory.getLog(CooEventFIPAACLMessage.class);
public CooEventFIPAACLMessage() {
}
public void dd(CooAgent anAgent) {
//TODO
if (logger.isErrorEnabled()) {
logger.error("dd() - Dispatching of FIPA ACL Message " +
"not yet implemented", null);
}
}
}
CooWS/src/org/coows/ICooAction.java 0000644 0001750 0001750 00000000225 10243705212 020211 0 ustar joshua joshua 0000000 0000000 package org.coows;
/**
* The interface for the implementations of success/failure actions
*
*/
public interface ICooAction {
void exec();
}
CooWS/src/org/coows/ICooBpelProcess.java 0000664 0001750 0001750 00000001226 10261247752 021233 0 ustar joshua joshua 0000000 0000000 package org.coows;
import org.coows.engine.CooException;
/**
* Define the interface for the BpelProcess
*
*/
public interface ICooBpelProcess {
/** Get the service name of the bpel process */
public String getServiceName();
/**
* Deploy the process to the bpel engine
*
* @throws CooException
*/
public void deploy() throws CooException;
/**
* Invoke the process using the given parameters
* @param p the parameters (a wrapper class)
* @throws CooException
*/
public void invoke(CooBpelProcessParameters p) throws CooException;
/**
* Undeploys the process
*
*/
public void undeploy();
}
CooWS/src/org/coows/CooAccessSpecifierPublic.java 0000664 0001750 0001750 00000001467 10257017151 023073 0 ustar joshua joshua 0000000 0000000 package org.coows;
/**
* Singleton class for the PUBLIC access specifier
*/
public class CooAccessSpecifierPublic
extends CooAbstractAccessSpecifier {
/**
*
* @uml.property name="instance"
* @uml.associationEnd multiplicity="(0 1)"
*/
private static final CooAccessSpecifierPublic instance = new CooAccessSpecifierPublic();
/**
* Constructor
*
* @param aAccSpec
*/
public CooAccessSpecifierPublic() {
super("PUBLIC");
}
/**
*
* @uml.property name="instance"
*/
public static CooAccessSpecifierPublic getInstance() {
return instance;
}
/**
* @see org.coows.CooAbstractAccessSpecifier#isTrusted(java.lang.String)
*/
public boolean isTrusted(String anAgentID) {
return true;
}
} CooWS/src/org/coows/package.html 0000644 0001750 0001750 00000000104 10204377124 017640 0 ustar joshua joshua 0000000 0000000
CooWS root package
CooWS/src/org/coows/CooAccessSpecifierPrivate.java 0000664 0001750 0001750 00000001405 10257017152 023260 0 ustar joshua joshua 0000000 0000000 package org.coows;
/**
* Singleton class for the PRIVATE access specifier
*/
public class CooAccessSpecifierPrivate
extends CooAbstractAccessSpecifier {
/**
*
* @uml.property name="mInstance"
* @uml.associationEnd multiplicity="(0 1)"
*/
private static final CooAccessSpecifierPrivate mInstance = new CooAccessSpecifierPrivate();
/**
* Constructor
*
* @param aAccSpec
*/
public CooAccessSpecifierPrivate() {
super("PRIVATE");
}
public static CooAccessSpecifierPrivate getInstance() {
return mInstance;
}
/**
* @see org.coows.CooAbstractAccessSpecifier#isTrusted(java.lang.String)
*/
public boolean isTrusted(String anAgentID) {
return false;
}
}
CooWS/src/org/package.html 0000644 0001750 0001750 00000000076 10204377603 016520 0 ustar joshua joshua 0000000 0000000
root package
CooWS/src/package.html 0000644 0001750 0001750 00000000076 10204377527 015736 0 ustar joshua joshua 0000000 0000000
root package
CooWS/bpel/ 0000755 0001750 0001750 00000000000 10247343452 013602 5 ustar joshua joshua 0000000 0000000 CooWS/bpel/plan1/ 0000755 0001750 0001750 00000000000 10222010276 014601 5 ustar joshua joshua 0000000 0000000 CooWS/bpel/plan1/bpel/ 0000755 0001750 0001750 00000000000 10222010755 015525 5 ustar joshua joshua 0000000 0000000 CooWS/bpel/plan1/bpel/plan1.bpel 0000644 0001750 0001750 00000001527 10211110502 017376 0 ustar joshua joshua 0000000 0000000