Overlord SVN: r245 - in sam/trunk/modules: core/src/main/java/org/jboss/sam/internal/common and 3 other directories.
by overlord-commits@lists.jboss.org
Author: heiko.braun(a)jboss.com
Date: 2008-08-14 03:43:37 -0400 (Thu, 14 Aug 2008)
New Revision: 245
Added:
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/common/
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/common/MapEventMessage.java
Removed:
sam/trunk/modules/core/src/test/java/org/jboss/test/sam/MapEventMessage.java
sam/trunk/modules/fx/src/test/java/org/jboss/test/sam/MapEventMessage.java
Modified:
sam/trunk/modules/fx/src/test/java/org/jboss/test/sam/chart/BarChartRunner.java
sam/trunk/modules/fx/src/test/java/org/jboss/test/sam/chart/LineChartRunner.java
sam/trunk/modules/fx/src/test/java/org/jboss/test/sam/chart/PieChartRunner.java
Log:
Move MapEventMessage to common package
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/common/MapEventMessage.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/common/MapEventMessage.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/common/MapEventMessage.java 2008-08-14 07:43:37 UTC (rev 245)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.internal.common;
+
+import org.jboss.sam.EventMessage;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class MapEventMessage implements EventMessage<Map>
+{
+ private Map<String, Object> data = new HashMap<String, Object>();
+
+ private long timestamp;
+
+ public MapEventMessage(Map<String, Object> data)
+ {
+ this.data = data;
+ }
+
+ public MapEventMessage()
+ {
+ this(System.currentTimeMillis());
+ }
+
+ public MapEventMessage(long timestamp)
+ {
+ this.timestamp = timestamp;
+ }
+
+ public MapEventMessage put(String key, Object value)
+ {
+ data.put(key, value);
+ return this;
+ }
+
+ public Object getProperty(String name)
+ {
+ return data.get(name);
+ }
+
+ public Map getUnderlying()
+ {
+ return data;
+ }
+
+ public long getTimestamp()
+ {
+ return this.timestamp;
+ }
+
+ public Iterator<String> getPropertyNames()
+ {
+ return this.data.keySet().iterator();
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/common/MapEventMessage.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Deleted: sam/trunk/modules/core/src/test/java/org/jboss/test/sam/MapEventMessage.java
===================================================================
--- sam/trunk/modules/core/src/test/java/org/jboss/test/sam/MapEventMessage.java 2008-08-13 14:54:11 UTC (rev 244)
+++ sam/trunk/modules/core/src/test/java/org/jboss/test/sam/MapEventMessage.java 2008-08-14 07:43:37 UTC (rev 245)
@@ -1,74 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.sam;
-
-import org.jboss.sam.EventMessage;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * @author Heiko.Braun <heiko.braun(a)jboss.com>
- */
-public class MapEventMessage implements EventMessage<Map>
-{
- private Map<String, Object> data = new HashMap<String, Object>();
-
- private long timestamp;
-
- public MapEventMessage()
- {
- this(System.currentTimeMillis());
- }
-
- public MapEventMessage(long timestamp)
- {
- this.timestamp = timestamp;
- }
-
- public MapEventMessage put(String key, Object value)
- {
- data.put(key, value);
- return this;
- }
-
- public Object getProperty(String name)
- {
- return data.get(name);
- }
-
- public Map getUnderlying()
- {
- return data;
- }
-
- public long getTimestamp()
- {
- return this.timestamp;
- }
-
- public Iterator<String> getPropertyNames()
- {
- return this.data.keySet().iterator();
- }
-}
Deleted: sam/trunk/modules/fx/src/test/java/org/jboss/test/sam/MapEventMessage.java
===================================================================
--- sam/trunk/modules/fx/src/test/java/org/jboss/test/sam/MapEventMessage.java 2008-08-13 14:54:11 UTC (rev 244)
+++ sam/trunk/modules/fx/src/test/java/org/jboss/test/sam/MapEventMessage.java 2008-08-14 07:43:37 UTC (rev 245)
@@ -1,74 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.sam;
-
-import org.jboss.sam.EventMessage;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * @author Heiko.Braun <heiko.braun(a)jboss.com>
- */
-public class MapEventMessage implements EventMessage<Map>
-{
- private Map<String, Object> data = new HashMap<String, Object>();
-
- private long timestamp;
-
- public MapEventMessage()
- {
- this(System.currentTimeMillis());
- }
-
- public MapEventMessage(long timestamp)
- {
- this.timestamp = timestamp;
- }
-
- public MapEventMessage put(String key, Object value)
- {
- data.put(key, value);
- return this;
- }
-
- public Object getProperty(String name)
- {
- return data.get(name);
- }
-
- public Map getUnderlying()
- {
- return data;
- }
-
- public long getTimestamp()
- {
- return this.timestamp;
- }
-
- public Iterator<String> getPropertyNames()
- {
- return this.data.keySet().iterator();
- }
-}
Modified: sam/trunk/modules/fx/src/test/java/org/jboss/test/sam/chart/BarChartRunner.java
===================================================================
--- sam/trunk/modules/fx/src/test/java/org/jboss/test/sam/chart/BarChartRunner.java 2008-08-13 14:54:11 UTC (rev 244)
+++ sam/trunk/modules/fx/src/test/java/org/jboss/test/sam/chart/BarChartRunner.java 2008-08-14 07:43:37 UTC (rev 245)
@@ -27,7 +27,7 @@
import org.jboss.sam.chart.PropertyMapping;
import org.jboss.sam.chart.internal.jfree.BarChartBuilder;
import org.jboss.test.sam.JFreeChartViewer;
-import org.jboss.test.sam.MapEventMessage;
+import org.jboss.sam.internal.common.MapEventMessage;
import org.jfree.chart.JFreeChart;
import java.util.ArrayList;
Modified: sam/trunk/modules/fx/src/test/java/org/jboss/test/sam/chart/LineChartRunner.java
===================================================================
--- sam/trunk/modules/fx/src/test/java/org/jboss/test/sam/chart/LineChartRunner.java 2008-08-13 14:54:11 UTC (rev 244)
+++ sam/trunk/modules/fx/src/test/java/org/jboss/test/sam/chart/LineChartRunner.java 2008-08-14 07:43:37 UTC (rev 245)
@@ -27,7 +27,7 @@
import org.jboss.sam.chart.PropertyMapping;
import org.jboss.sam.chart.internal.jfree.LineChartBuilder;
import org.jboss.test.sam.JFreeChartViewer;
-import org.jboss.test.sam.MapEventMessage;
+import org.jboss.sam.internal.common.MapEventMessage;
import org.jfree.chart.JFreeChart;
import java.util.ArrayList;
Modified: sam/trunk/modules/fx/src/test/java/org/jboss/test/sam/chart/PieChartRunner.java
===================================================================
--- sam/trunk/modules/fx/src/test/java/org/jboss/test/sam/chart/PieChartRunner.java 2008-08-13 14:54:11 UTC (rev 244)
+++ sam/trunk/modules/fx/src/test/java/org/jboss/test/sam/chart/PieChartRunner.java 2008-08-14 07:43:37 UTC (rev 245)
@@ -27,7 +27,7 @@
import org.jboss.sam.chart.PropertyMapping;
import org.jboss.sam.chart.internal.jfree.PieChartBuilder;
import org.jboss.test.sam.JFreeChartViewer;
-import org.jboss.test.sam.MapEventMessage;
+import org.jboss.sam.internal.common.MapEventMessage;
import org.jfree.chart.JFreeChart;
import java.util.ArrayList;
15 years, 9 months
Overlord SVN: r244 - in sam/trunk/modules/core/src: test/java/org/jboss/test/sam/database and 1 other directories.
by overlord-commits@lists.jboss.org
Author: heiko.braun(a)jboss.com
Date: 2008-08-13 10:54:11 -0400 (Wed, 13 Aug 2008)
New Revision: 244
Added:
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/MapMessageAdapter.java
Modified:
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/ObjectMessageAdaptor.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/SAMAdapter.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/StreamOutputAdapter.java
sam/trunk/modules/core/src/test/java/org/jboss/test/sam/database/DatabaseTestCase.java
sam/trunk/modules/core/src/test/resources/database/test.drl
Log:
Added MapMessageAdater to cope with SQL query results as event streams
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/MapMessageAdapter.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/MapMessageAdapter.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/MapMessageAdapter.java 2008-08-13 14:54:11 UTC (rev 244)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.internal.drools;
+
+import org.jboss.sam.EventMessage;
+
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class MapMessageAdapter implements EventMessage
+{
+
+ private Map delegate;
+
+ public MapMessageAdapter(Map delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ public long getTimestamp()
+ {
+ return (Long)delegate.get("timestamp");
+ }
+
+ public Object getProperty(String name)
+ {
+ return delegate.get(name);
+ }
+
+ public Iterator getPropertyNames()
+ {
+ return delegate.keySet().iterator();
+ }
+
+ public Object getUnderlying()
+ {
+ return delegate;
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/MapMessageAdapter.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/ObjectMessageAdaptor.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/ObjectMessageAdaptor.java 2008-08-13 14:42:18 UTC (rev 243)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/ObjectMessageAdaptor.java 2008-08-13 14:54:11 UTC (rev 244)
@@ -56,7 +56,7 @@
}
catch (Exception e)
{
- throw new RuntimeException("Proprty access error: "+methodName, e);
+ throw new RuntimeException("Property access error: "+methodName, e);
}
return returnValue;
}
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/SAMAdapter.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/SAMAdapter.java 2008-08-13 14:42:18 UTC (rev 243)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/SAMAdapter.java 2008-08-13 14:54:11 UTC (rev 244)
@@ -98,13 +98,15 @@
Map row = new HashMap();
for(int i=1;i<=numcols;i++)
{
- row.put(rset.getMetaData().getColumnName(i), rset.getObject(i));
+ // TODO: case handling should be configureable
+ row.put(rset.getMetaData().getColumnName(i).toLowerCase(), rset.getObject(i));
}
results.add(row);
}
}
catch(SQLException e)
{
+ // todo: exeception handling? (Goes back into drools)
e.printStackTrace();
}
finally
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/StreamOutputAdapter.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/StreamOutputAdapter.java 2008-08-13 14:42:18 UTC (rev 243)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/StreamOutputAdapter.java 2008-08-13 14:54:11 UTC (rev 244)
@@ -25,6 +25,7 @@
import org.jboss.sam.EventMessage;
import java.util.Collection;
+import java.util.Map;
/**
* @author Heiko.Braun <heiko.braun(a)jboss.com>
@@ -60,7 +61,11 @@
events = new EventMessage[c.size()];
for(int i=0; i<c.size(); i++)
{
- events[i] = new ObjectMessageAdaptor(cAr[i]);
+ // TODO: think more thoroughly about payload adoption
+ if(cAr[i] instanceof Map)
+ events[i] = new MapMessageAdapter((Map)cAr[i]);
+ else
+ events[i] = new ObjectMessageAdaptor(cAr[i]);
}
}
else
Modified: sam/trunk/modules/core/src/test/java/org/jboss/test/sam/database/DatabaseTestCase.java
===================================================================
--- sam/trunk/modules/core/src/test/java/org/jboss/test/sam/database/DatabaseTestCase.java 2008-08-13 14:42:18 UTC (rev 243)
+++ sam/trunk/modules/core/src/test/java/org/jboss/test/sam/database/DatabaseTestCase.java 2008-08-13 14:54:11 UTC (rev 244)
@@ -87,10 +87,11 @@
// evaluate
assertTrue("Listener not invoked", bufferedOutput.isInvoked());
EventMessage[] eventMessages = bufferedOutput.getLastNewData();
+ assertEquals(7, eventMessages.length);
for(EventMessage event : eventMessages)
{
- System.out.println("!! " + event.getUnderlying() );
+ System.out.println(event.getProperty("symbol") + " -> " + event.getProperty("price") );
}
}
Modified: sam/trunk/modules/core/src/test/resources/database/test.drl
===================================================================
--- sam/trunk/modules/core/src/test/resources/database/test.drl 2008-08-13 14:42:18 UTC (rev 243)
+++ sam/trunk/modules/core/src/test/resources/database/test.drl 2008-08-13 14:54:11 UTC (rev 244)
@@ -8,7 +8,7 @@
when
$query: Query();
$sqlStream: ArrayList() from collect (
- Map() from SAM.query("hsqlDB", "SELECT * FROM quotes WHERE symbol='"+$query.criteria+"'")
+ Map() from SAM.query("hsqlDB", "SELECT * FROM quotes")
);
then
SAM.getListener("InVM").update($sqlStream);
15 years, 9 months
Overlord SVN: r243 - in sam/trunk/modules/core/src: main/java/org/jboss/sam/config and 10 other directories.
by overlord-commits@lists.jboss.org
Author: heiko.braun(a)jboss.com
Date: 2008-08-13 10:42:18 -0400 (Wed, 13 Aug 2008)
New Revision: 243
Added:
sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntimeAware.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/
sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/DataSourceFactory.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/DataSourceManager.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/internal/
sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/internal/DBCPDataSourceFactory.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/DefaultRuntimeFactory.java
sam/trunk/modules/core/src/test/resources/drools/sam-cfg.xml
Removed:
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/
Modified:
sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessor.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntime.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntimeFactory.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/config/Configurator.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/DefaultRuntimeImpl.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsEventProcessorImpl.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/SAMAdapter.java
sam/trunk/modules/core/src/test/java/org/jboss/test/sam/InMemoryDatabase.java
sam/trunk/modules/core/src/test/java/org/jboss/test/sam/SamTestSetup.java
sam/trunk/modules/core/src/test/java/org/jboss/test/sam/adapter/invm/InVMAdapterTestCase.java
sam/trunk/modules/core/src/test/java/org/jboss/test/sam/database/DatabaseTestCase.java
sam/trunk/modules/core/src/test/java/org/jboss/test/sam/drools/ApiTestCase.java
sam/trunk/modules/core/src/test/resources/database/sam-cfg.xml
sam/trunk/modules/core/src/test/resources/database/test.drl
Log:
Force usage of SAMRuntimeFactory, otherwise the EventProcessor wouldn't be configured (or it needs to be done explicitly)
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessor.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessor.java 2008-08-13 14:40:01 UTC (rev 242)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessor.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -28,11 +28,11 @@
* and provides a way to register {@link org.jboss.sam.ProcessingStatement}'s,
* both bound (event forwarding) and unbound (event aggregation and filtering).
* <p>
- * Instances are created through {@link org.jboss.sam.EventProcessorFactory}
+ * Instances are created through {@link org.jboss.sam.EventProcessorFactory}
*
* @author Heiko.Braun <heiko.braun(a)jboss.com>
*/
-public interface EventProcessor<T>
+public interface EventProcessor<T> extends SAMRuntimeAware
{
/**
* Add input to the runtime
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntime.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntime.java 2008-08-13 14:40:01 UTC (rev 242)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntime.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -21,30 +21,20 @@
*/
package org.jboss.sam;
+import org.jboss.sam.datasource.DataSourceManager;
import org.jboss.sam.config.Configurator;
-import org.jboss.sam.internal.datasource.DatasourceManager;
+
/**
+ * Glues together SAM building blocks.
+ *
* @author Heiko.Braun <heiko.braun(a)jboss.com>
*/
-public abstract class SAMRuntime
+public interface SAMRuntime
{
- private Configurator configurator;
+ void applyConfiguration(Configurator cfg);
- private EventProcessor eventProcessor;
- private DatasourceManager datasourceManager;
+ DataSourceManager getDataSourceManager();
- protected SAMRuntime(Configurator configurator)
- {
- this.configurator = configurator;
-
- // create and configure a processor
- this.eventProcessor = EventProcessorFactory.newInstance().createProcessor();
- configurator.configure(this.eventProcessor);
-
- // create and configure datasources
- this.datasourceManager = new DatasourceManager();
- configurator.configure(datasourceManager);
-
- }
+ EventProcessor getEventProcessor();
}
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntimeAware.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntimeAware.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntimeAware.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam;
+
+/**
+ * Marks SAM components that need to interact with the runtime itself.
+ *
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public interface SAMRuntimeAware
+{
+ void setRuntime(SAMRuntime runtime);
+}
+
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntimeAware.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntimeFactory.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntimeFactory.java 2008-08-13 14:40:01 UTC (rev 242)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntimeFactory.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -22,26 +22,17 @@
package org.jboss.sam;
import org.jboss.sam.config.Configurator;
-import org.jboss.sam.internal.DefaultRuntimeImpl;
+import org.jboss.sam.internal.DefaultRuntimeFactory;
/**
* @author Heiko.Braun <heiko.braun(a)jboss.com>
*/
public abstract class SAMRuntimeFactory
{
-
public abstract SAMRuntime createRuntime(Configurator configurator);
public static SAMRuntimeFactory newInstance()
{
return new DefaultRuntimeFactory();
- }
-
- static class DefaultRuntimeFactory extends SAMRuntimeFactory
- {
- public SAMRuntime createRuntime(Configurator configurator)
- {
- return new DefaultRuntimeImpl(configurator);
- }
- }
+ }
}
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/Configurator.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/config/Configurator.java 2008-08-13 14:40:01 UTC (rev 242)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/config/Configurator.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -24,8 +24,8 @@
import org.jboss.sam.EventProcessor;
import org.jboss.sam.StreamInput;
import org.jboss.sam.StreamOutput;
-import org.jboss.sam.internal.datasource.DatasourceManager;
-import org.jboss.sam.internal.datasource.DataSourceFactory;
+import org.jboss.sam.datasource.DataSourceManager;
+import org.jboss.sam.datasource.DataSourceFactory;
import javax.sql.DataSource;
@@ -88,7 +88,7 @@
}
}
- public void configure(DatasourceManager manager)
+ public void configure(DataSourceManager manager)
{
DataSourceFactory dsFactory = DataSourceFactory.newInstance();
Copied: sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/DataSourceFactory.java (from rev 241, sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DataSourceFactory.java)
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/DataSourceFactory.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/DataSourceFactory.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.datasource;
+
+import org.jboss.sam.config.DataSourceDef;
+import org.jboss.sam.datasource.internal.DBCPDataSourceFactory;
+
+import javax.sql.DataSource;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public abstract class DataSourceFactory
+{
+ public static DataSourceFactory newInstance()
+ {
+ return new DBCPDataSourceFactory();
+ }
+
+ public abstract DataSource createDataSource(DataSourceDef dsDef);
+
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/DataSourceFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/DataSourceManager.java (from rev 241, sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DatasourceManager.java)
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/DataSourceManager.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/DataSourceManager.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.datasource;
+
+import javax.sql.DataSource;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class DataSourceManager
+{
+ private Map<String, DataSource> datasources = new ConcurrentHashMap<String, DataSource>();
+
+ public void addDataSource(String reference, DataSource ds)
+ {
+ if(datasources.containsKey(reference))
+ throw new IllegalArgumentException("DataSource '" + reference + "' does already exist!");
+
+ this.datasources.put(reference, ds);
+ }
+
+ public DataSource getDataSource(String reference)
+ {
+ DataSource ds = datasources.get(reference);
+ if(null==ds)
+ throw new IllegalArgumentException("No DataSource for reference '" + reference + "'");
+
+ return ds;
+ }
+
+ public boolean hasDataSource(String reference)
+ {
+ return datasources.containsKey(reference);
+ }
+
+
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/DataSourceManager.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/internal/DBCPDataSourceFactory.java (from rev 241, sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DBCPDataSourceFactory.java)
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/internal/DBCPDataSourceFactory.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/internal/DBCPDataSourceFactory.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.datasource.internal;
+
+import org.jboss.sam.config.DataSourceDef;
+import org.jboss.sam.datasource.DataSourceFactory;
+import org.apache.commons.pool.ObjectPool;
+import org.apache.commons.pool.impl.GenericObjectPool;
+import org.apache.commons.dbcp.ConnectionFactory;
+import org.apache.commons.dbcp.DriverManagerConnectionFactory;
+import org.apache.commons.dbcp.PoolableConnectionFactory;
+import org.apache.commons.dbcp.PoolingDataSource;
+
+import javax.sql.DataSource;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class DBCPDataSourceFactory extends DataSourceFactory
+{
+
+ public DBCPDataSourceFactory()
+ {
+ }
+
+ public DataSource createDataSource(DataSourceDef dsDef)
+ {
+ try {
+ Class.forName(dsDef.getDriver());
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException("Failed to load JDBC driver: " + dsDef.getDriver(), e);
+ }
+
+ //
+ // First, we'll need a ObjectPool that serves as the
+ // actual pool of connections.
+ //
+ // We'll use a GenericObjectPool instance, although
+ // any ObjectPool implementation will suffice.
+ //
+ ObjectPool connectionPool = new GenericObjectPool(null);
+
+ //
+ // Next, we'll create a ConnectionFactory that the
+ // pool will use to create Connections.
+ // We'll use the DriverManagerConnectionFactory,
+ // using the connect string passed in the command line
+ // arguments.
+ //
+ ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(dsDef.getUrl(),null);
+
+ //
+ // Now we'll create the PoolableConnectionFactory, which wraps
+ // the "real" Connections created by the ConnectionFactory with
+ // the classes that implement the pooling functionality.
+ //
+ PoolableConnectionFactory poolableConnectionFactory =
+ new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
+
+ //
+ // Finally, we create the PoolingDriver itself,
+ // passing in the object pool we created.
+ //
+ PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
+
+ return dataSource;
+
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/datasource/internal/DBCPDataSourceFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/DefaultRuntimeFactory.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/DefaultRuntimeFactory.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/DefaultRuntimeFactory.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.internal;
+
+import org.jboss.sam.SAMRuntimeFactory;
+import org.jboss.sam.SAMRuntime;
+import org.jboss.sam.config.Configurator;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class DefaultRuntimeFactory extends SAMRuntimeFactory
+{
+ public SAMRuntime createRuntime(Configurator configurator)
+ {
+ DefaultRuntimeImpl defaultRuntime = new DefaultRuntimeImpl();
+ defaultRuntime.applyConfiguration(configurator);
+ return defaultRuntime;
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/DefaultRuntimeFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/DefaultRuntimeImpl.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/DefaultRuntimeImpl.java 2008-08-13 14:40:01 UTC (rev 242)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/DefaultRuntimeImpl.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -22,16 +22,45 @@
package org.jboss.sam.internal;
import org.jboss.sam.SAMRuntime;
+import org.jboss.sam.EventProcessor;
+import org.jboss.sam.EventProcessorFactory;
+import org.jboss.sam.SAMRuntimeAware;
+import org.jboss.sam.datasource.DataSourceManager;
import org.jboss.sam.config.Configurator;
/**
+ * Glues together SAM building blocks.
+ *
* @author Heiko.Braun <heiko.braun(a)jboss.com>
*/
-public class DefaultRuntimeImpl extends SAMRuntime
+public class DefaultRuntimeImpl implements SAMRuntime
{
+ private EventProcessor eventProcessor;
+ private DataSourceManager dataSourceManager;
- public DefaultRuntimeImpl(Configurator configurator)
+ DefaultRuntimeImpl()
{
- super(configurator);
+ // create and configure a processor
+ this.eventProcessor = EventProcessorFactory.newInstance().createProcessor();
+ ((SAMRuntimeAware)this.eventProcessor).setRuntime(this);
+
+ // create and configure datasources
+ this.dataSourceManager = new DataSourceManager();
}
+
+ public void applyConfiguration(Configurator cfg)
+ {
+ cfg.configure(this.eventProcessor);
+ cfg.configure(this.dataSourceManager);
+ }
+
+ public DataSourceManager getDataSourceManager()
+ {
+ return this.dataSourceManager;
+ }
+
+ public EventProcessor getEventProcessor()
+ {
+ return this.eventProcessor;
+ }
}
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsEventProcessorImpl.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsEventProcessorImpl.java 2008-08-13 14:40:01 UTC (rev 242)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsEventProcessorImpl.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -31,6 +31,7 @@
import org.drools.lang.descr.PackageDescr;
import org.drools.spi.GlobalResolver;
import org.jboss.sam.*;
+import org.jboss.sam.datasource.DataSourceManager;
import java.io.*;
import java.util.Iterator;
@@ -57,8 +58,8 @@
private Map<String, Object> wmGlobals = new ConcurrentHashMap<String, Object>();
private Map<String, StreamOutputAdapter> outputAdapters = new ConcurrentHashMap<String, StreamOutputAdapter>();
- private final static String SAM_ADAPTER_NAME = "SAM";
-
+ private SAMRuntime runtime;
+
public DroolsEventProcessorImpl()
{
try
@@ -73,13 +74,21 @@
}
}
+ public void setRuntime(SAMRuntime runtime)
+ {
+ this.runtime = runtime;
+ }
+
public Object resolveGlobal(String key)
{
+ assert runtime!=null : "Runtime not set!";
+
Object global = null;
- if(SAM_ADAPTER_NAME.equals(key))
- {
- global = new SAMAdapter(this.session, this.outputAdapters);
+ if("SAM".equals(key))
+ {
+ DataSourceManager dsMgr = this.runtime.getDataSourceManager();
+ global = new SAMAdapter(this.session, this.outputAdapters, dsMgr);
}
else
{
@@ -109,10 +118,10 @@
}
public void onEvent(Object args)
- {
+ {
session.insert(args);
- // TODO: shouldn't be necessary
+ // TODO: shouldn't be necessary, revisit!
session.fireAllRules();
}
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/SAMAdapter.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/SAMAdapter.java 2008-08-13 14:40:01 UTC (rev 242)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/SAMAdapter.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -23,15 +23,21 @@
import org.drools.StatefulSession;
import org.drools.WorkingMemoryEntryPoint;
+import org.jboss.sam.datasource.DataSourceManager;
+import javax.sql.DataSource;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.sql.SQLException;
/**
- * Will be injected into WorkingMemory to give access drools entities that
- * are relevant to the SAM processing model. This class basically acts as a workaround for
- * features that we would like to see:
+ * Will be injected into WorkingMemory to give drools access to SAM extensions.<br>
+ * This class basically acts as a workaround for features that we would like to see:
*
* <ul>
* <li>Hidden behind a custom SAM DSL
@@ -44,11 +50,13 @@
{
private StatefulSession session;
private Map<String, StreamOutputAdapter> outputAdapters;
+ private DataSourceManager datasourceManager;
- public SAMAdapter(StatefulSession session, Map<String, StreamOutputAdapter> outputAdapters)
+ public SAMAdapter(StatefulSession session, Map<String, StreamOutputAdapter> outputAdapters, DataSourceManager dsMgr)
{
this.session = session;
this.outputAdapters = outputAdapters;
+ this.datasourceManager = dsMgr;
}
public WorkingMemoryEntryPoint getStream(String name)
@@ -68,12 +76,44 @@
return adapter;
}
- public List executeSQL(String dbName, String sql)
+ public List query(String dbName, String sql)
{
- System.out.println("SQL: " + sql);
+ DataSource dataSource = datasourceManager.getDataSource(dbName);
ArrayList results = new ArrayList();
- results.add("Hello");
- results.add("World");
+
+ Connection conn = null;
+ Statement stmt = null;
+ ResultSet rset = null;
+
+ try
+ {
+ conn = dataSource.getConnection();
+ stmt = conn.createStatement();
+ rset = stmt.executeQuery(sql);
+
+ int numcols = rset.getMetaData().getColumnCount();
+
+ while(rset.next())
+ {
+ Map row = new HashMap();
+ for(int i=1;i<=numcols;i++)
+ {
+ row.put(rset.getMetaData().getColumnName(i), rset.getObject(i));
+ }
+ results.add(row);
+ }
+ }
+ catch(SQLException e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try { rset.close(); } catch(Exception e) { }
+ try { stmt.close(); } catch(Exception e) { }
+ try { conn.close(); } catch(Exception e) { }
+ }
+
return results;
}
}
Modified: sam/trunk/modules/core/src/test/java/org/jboss/test/sam/InMemoryDatabase.java
===================================================================
--- sam/trunk/modules/core/src/test/java/org/jboss/test/sam/InMemoryDatabase.java 2008-08-13 14:40:01 UTC (rev 242)
+++ sam/trunk/modules/core/src/test/java/org/jboss/test/sam/InMemoryDatabase.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -21,6 +21,7 @@
*/
package org.jboss.test.sam;
+import javax.sql.DataSource;
import java.sql.*;
/**
@@ -43,6 +44,18 @@
private static final String USER = "sa";
private static final String PASSWORD = "";
+
+ public InMemoryDatabase(DataSource dataSource)
+ {
+ try
+ {
+ conn = dataSource.getConnection();
+ } catch (SQLException e)
+ {
+ throw new RuntimeException("Failed to setup HSQL database", e);
+ }
+ }
+
public InMemoryDatabase()
{
try
@@ -97,7 +110,7 @@
}
st.close();
- } // void update()
+ }
public void shutdown() throws SQLException {
Modified: sam/trunk/modules/core/src/test/java/org/jboss/test/sam/SamTestSetup.java
===================================================================
--- sam/trunk/modules/core/src/test/java/org/jboss/test/sam/SamTestSetup.java 2008-08-13 14:40:01 UTC (rev 242)
+++ sam/trunk/modules/core/src/test/java/org/jboss/test/sam/SamTestSetup.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -22,14 +22,13 @@
package org.jboss.test.sam;
import junit.framework.TestCase;
-import org.jboss.sam.EventProcessor;
-import org.jboss.sam.EventProcessorFactory;
-import org.jboss.sam.StreamInput;
+import org.jboss.sam.*;
import org.jboss.sam.config.ConfigFactory;
import org.jboss.sam.config.Configurator;
import org.jboss.sam.internal.stream.InVMDispatcher;
import org.jboss.sam.internal.stream.InVMStreamInput;
+import javax.sql.DataSource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -42,6 +41,7 @@
*/
public abstract class SamTestSetup extends TestCase
{
+ protected SAMRuntime runtime;
protected EventProcessor eventProcessor;
protected StreamInput streamInput;
protected BufferedStreamOutput bufferedOutput;
@@ -57,19 +57,18 @@
* @param name the runtime name
* @param configFile name of the esper-config file relative to test execution
*/
- public void createProcessorWithDefaultIO(String name, String configFile)
+ public void createProcessor(String name, String configFile)
{
+ assert configFile!=null : "No configFile!";
+
// Main runtime
- eventProcessor = EventProcessorFactory.newInstance().createProcessor();
+ URL config = loadTestConfiguration(configFile);
+ Configurator configurator = new Configurator( ConfigFactory.newInstance().unmarshall(config) );
- URL config = configFile!=null ? loadTestConfiguration(configFile) : null;
- if(config!=null)
- {
- Configurator configurator = new Configurator( ConfigFactory.newInstance().unmarshall(config) );
- configurator.configure(eventProcessor);
- }
+ runtime = SAMRuntimeFactory.newInstance().createRuntime(configurator);
+ eventProcessor = runtime.getEventProcessor();
- // Stream input and output
+ // Stream input and output
streamInput = new InVMStreamInput("InVM").start();
dispatcher = new InVMDispatcher(streamInput.getStreamName());
@@ -89,6 +88,13 @@
return inMemoryDB;
}
+ protected InMemoryDatabase createDatabase(DataSource dataSource)
+ {
+ InMemoryDatabase inMemoryDB = new InMemoryDatabase(dataSource);
+ System.out.println("Database has been setup: " + inMemoryDB);
+ return inMemoryDB;
+ }
+
protected void generateInVMEvent(Object obj)
{
dispatcher.dispatch(obj);
Modified: sam/trunk/modules/core/src/test/java/org/jboss/test/sam/adapter/invm/InVMAdapterTestCase.java
===================================================================
--- sam/trunk/modules/core/src/test/java/org/jboss/test/sam/adapter/invm/InVMAdapterTestCase.java 2008-08-13 14:40:01 UTC (rev 242)
+++ sam/trunk/modules/core/src/test/java/org/jboss/test/sam/adapter/invm/InVMAdapterTestCase.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -21,7 +21,6 @@
*/
package org.jboss.test.sam.adapter.invm;
-import org.jboss.sam.ProcessingStatement;
import org.jboss.test.sam.SamTestSetup;
/**
@@ -31,7 +30,7 @@
{
public void setUp()
{
- createProcessorWithDefaultIO("InVMAdapterTestCase", "adapter/invm/sam-cfg.xml");
+ createProcessor("InVMAdapterTestCase", "adapter/invm/sam-cfg.xml");
}
public void testAdapter() throws Exception
Modified: sam/trunk/modules/core/src/test/java/org/jboss/test/sam/database/DatabaseTestCase.java
===================================================================
--- sam/trunk/modules/core/src/test/java/org/jboss/test/sam/database/DatabaseTestCase.java 2008-08-13 14:40:01 UTC (rev 242)
+++ sam/trunk/modules/core/src/test/java/org/jboss/test/sam/database/DatabaseTestCase.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -37,11 +37,13 @@
public void setUp() throws Exception
{
// Runtime
- createProcessorWithDefaultIO("DataBaseTestCase", "database/sam-cfg.xml");
+ createProcessor("DataBaseTestCase", "database/sam-cfg.xml");
// InMemory Database
- db = createDatabase();
-
+ db = createDatabase(
+ runtime.getDataSourceManager().getDataSource("hsqlDB")
+ );
+
// test schema
db.update("CREATE TABLE quotes (" +
" symbol varchar(10) NOT NULL," +
@@ -89,7 +91,7 @@
for(EventMessage event : eventMessages)
{
System.out.println("!! " + event.getUnderlying() );
- }
+ }
}
public void testEsperPullAPI() throws Exception
Modified: sam/trunk/modules/core/src/test/java/org/jboss/test/sam/drools/ApiTestCase.java
===================================================================
--- sam/trunk/modules/core/src/test/java/org/jboss/test/sam/drools/ApiTestCase.java 2008-08-13 14:40:01 UTC (rev 242)
+++ sam/trunk/modules/core/src/test/java/org/jboss/test/sam/drools/ApiTestCase.java 2008-08-13 14:42:18 UTC (rev 243)
@@ -34,7 +34,7 @@
protected void setUp() throws Exception
{
// Creates default adapter inputs and outputs
- createProcessorWithDefaultIO("ApiTestCase", null);
+ createProcessor("ApiTestCase", "drools/sam-cfg.xml");
}
public void testBoundStatement()
Modified: sam/trunk/modules/core/src/test/resources/database/sam-cfg.xml
===================================================================
--- sam/trunk/modules/core/src/test/resources/database/sam-cfg.xml 2008-08-13 14:40:01 UTC (rev 242)
+++ sam/trunk/modules/core/src/test/resources/database/sam-cfg.xml 2008-08-13 14:42:18 UTC (rev 243)
@@ -1,8 +1,23 @@
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<ns2:processingNode name="DatabaseTestCase"
- domain="http://org.jboss.sam/test/database"
+ domain="http://org.jboss.sam/test/database"
xmlns:ns2="http://org.jboss.sam/08/2008/">
+ <properties/>
+
+ <database-references>
+ <database-reference name="hsqlDB">
+ <datasource url="jdbc:hsqldb:mem:SamTestSetup" name="hsqlDS" driver="org.hsqldb.jdbcDriver">
+ <connection-arg value="sa" name="user"/>
+ <connection-arg value="" name="password"/>
+ </datasource>
+ </database-reference>
+ </database-references>
+
+ <inputs/>
+
+ <outputs/>
+
<statements/>
-
+
</ns2:processingNode>
\ No newline at end of file
Modified: sam/trunk/modules/core/src/test/resources/database/test.drl
===================================================================
--- sam/trunk/modules/core/src/test/resources/database/test.drl 2008-08-13 14:40:01 UTC (rev 242)
+++ sam/trunk/modules/core/src/test/resources/database/test.drl 2008-08-13 14:42:18 UTC (rev 243)
@@ -1,6 +1,6 @@
package org.jboss.test.sam.database;
-import java.util.ArrayList;
+import java.util.*;
global org.jboss.sam.internal.drools.SAMAdapter SAM;
@@ -8,7 +8,7 @@
when
$query: Query();
$sqlStream: ArrayList() from collect (
- String() from SAM.executeSQL("hsqlDB", "SELECT * FROM StockQuotes WHERE symbol='"+$query.criteria+"'")
+ Map() from SAM.query("hsqlDB", "SELECT * FROM quotes WHERE symbol='"+$query.criteria+"'")
);
then
SAM.getListener("InVM").update($sqlStream);
Added: sam/trunk/modules/core/src/test/resources/drools/sam-cfg.xml
===================================================================
--- sam/trunk/modules/core/src/test/resources/drools/sam-cfg.xml (rev 0)
+++ sam/trunk/modules/core/src/test/resources/drools/sam-cfg.xml 2008-08-13 14:42:18 UTC (rev 243)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
+<ns2:processingNode name="DatabaseTestCase"
+ domain="http://org.jboss.sam/test/database"
+ xmlns:ns2="http://org.jboss.sam/08/2008/">
+
+ <statements/>
+
+</ns2:processingNode>
\ No newline at end of file
Property changes on: sam/trunk/modules/core/src/test/resources/drools/sam-cfg.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
15 years, 9 months
Overlord SVN: r242 - in sam/trunk/modules/sim/src: test/java/org/jboss/test/sam/samples/aggregation and 4 other directories.
by overlord-commits@lists.jboss.org
Author: heiko.braun(a)jboss.com
Date: 2008-08-13 10:40:01 -0400 (Wed, 13 Aug 2008)
New Revision: 242
Added:
sam/trunk/modules/sim/src/test/resources/simulation/sam-cfg.xml
Modified:
sam/trunk/modules/sim/src/main/java/org/jboss/sam/simulation/EventSimulation.java
sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/samples/aggregation/AggregationTestCase.java
sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/samples/falloff/FalloffTestCase.java
sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/samples/filtering/FilteringTestCase.java
sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/simulation/SimulationTestCase.java
Log:
Provide default config to all simulation testcases
Modified: sam/trunk/modules/sim/src/main/java/org/jboss/sam/simulation/EventSimulation.java
===================================================================
--- sam/trunk/modules/sim/src/main/java/org/jboss/sam/simulation/EventSimulation.java 2008-08-13 12:54:02 UTC (rev 241)
+++ sam/trunk/modules/sim/src/main/java/org/jboss/sam/simulation/EventSimulation.java 2008-08-13 14:40:01 UTC (rev 242)
@@ -25,8 +25,11 @@
import org.javasim.SimulationException;
import org.javasim.SimulationProcess;
import org.jboss.sam.EventProcessor;
-import org.jboss.sam.EventProcessorFactory;
+import org.jboss.sam.SAMRuntime;
+import org.jboss.sam.SAMRuntimeFactory;
import org.jboss.sam.StreamInput;
+import org.jboss.sam.config.ConfigFactory;
+import org.jboss.sam.config.Configurator;
import org.jboss.sam.internal.stream.InVMDispatcher;
import org.jboss.sam.internal.stream.InVMStreamInput;
@@ -72,6 +75,7 @@
private InVMDispatcher dispatcher;
// SAM properties
+ private SAMRuntime runtime;
private EventProcessor eventProcessor;
private StreamInput streamInput;
@@ -81,15 +85,18 @@
private EventSimulation(Properties config, URL bootstrap)
{
+ assert bootstrap!=null : "Bootstrap config is null!";
+
// thread setup
- setName("EventSimulation {" + getName()+"}");
+ setName("EventSimulation {" + getName()+ "}");
setPriority(1);
this.context = new SimulationContext(config);
- // setup SAM processor
- this.eventProcessor = EventProcessorFactory.newInstance().createProcessor();
- this.eventProcessor.setName("EventSimulation");
+ // setup SAM runtime
+ Configurator configurator = new Configurator( ConfigFactory.newInstance().unmarshall(bootstrap) );
+ this.runtime = SAMRuntimeFactory.newInstance().createRuntime(configurator);
+ this.eventProcessor = runtime.getEventProcessor();
// create input for the default in-vm channel
this.streamInput = new InVMStreamInput(InVMDispatcher.DEFAULT_CHANNEL_NAME);
@@ -254,14 +261,7 @@
System.exit(-1);
}
}
-
- public static EventSimulation bootstrap(Properties config)
- {
- return new EventSimulation(config,
- Thread.currentThread().getContextClassLoader().getResource("samples/esper-default-cfg.xml")
- );
- }
-
+
public static EventSimulation bootstrap(Properties config, URL bootstrap)
{
return new EventSimulation(config, bootstrap);
Modified: sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/samples/aggregation/AggregationTestCase.java
===================================================================
--- sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/samples/aggregation/AggregationTestCase.java 2008-08-13 12:54:02 UTC (rev 241)
+++ sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/samples/aggregation/AggregationTestCase.java 2008-08-13 14:40:01 UTC (rev 242)
@@ -49,7 +49,9 @@
config.put(EventSimulation.TOTAL_SIM_TIME, 100.00);
// init
- simulation = EventSimulation.bootstrap(config);
+ simulation = EventSimulation.bootstrap(config,
+ Thread.currentThread().getContextClassLoader().getResource("simulation/sam-cfg.xml")
+ );
// shared between all entities
context = simulation.getContext();
Modified: sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/samples/falloff/FalloffTestCase.java
===================================================================
--- sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/samples/falloff/FalloffTestCase.java 2008-08-13 12:54:02 UTC (rev 241)
+++ sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/samples/falloff/FalloffTestCase.java 2008-08-13 14:40:01 UTC (rev 242)
@@ -47,7 +47,9 @@
config.put(EventSimulation.TOTAL_SIM_TIME, 100.00);
// init
- simulation = EventSimulation.bootstrap(config);
+ simulation = EventSimulation.bootstrap(config,
+ Thread.currentThread().getContextClassLoader().getResource("simulation/sam-cfg.xml")
+ );
// shared between all entities
context = simulation.getContext();
Modified: sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/samples/filtering/FilteringTestCase.java
===================================================================
--- sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/samples/filtering/FilteringTestCase.java 2008-08-13 12:54:02 UTC (rev 241)
+++ sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/samples/filtering/FilteringTestCase.java 2008-08-13 14:40:01 UTC (rev 242)
@@ -57,7 +57,9 @@
config.put(EventSimulation.TOTAL_SIM_TIME, 75.00);
// init
- simulation = EventSimulation.bootstrap(config);
+ simulation = EventSimulation.bootstrap(config,
+ Thread.currentThread().getContextClassLoader().getResource("simulation/sam-cfg.xml")
+ );
// shared between all entities
context = simulation.getContext();
Modified: sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/simulation/SimulationTestCase.java
===================================================================
--- sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/simulation/SimulationTestCase.java 2008-08-13 12:54:02 UTC (rev 241)
+++ sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/simulation/SimulationTestCase.java 2008-08-13 14:40:01 UTC (rev 242)
@@ -41,7 +41,9 @@
config.put(EventSimulation.TOTAL_SIM_TIME, 60.00);
// init
- EventSimulation simulation = EventSimulation.bootstrap(config);
+ EventSimulation simulation = EventSimulation.bootstrap(config,
+ Thread.currentThread().getContextClassLoader().getResource("simulation/sam-cfg.xml")
+ );
// shared between all entities
SimulationContext context = simulation.getContext();
Added: sam/trunk/modules/sim/src/test/resources/simulation/sam-cfg.xml
===================================================================
--- sam/trunk/modules/sim/src/test/resources/simulation/sam-cfg.xml (rev 0)
+++ sam/trunk/modules/sim/src/test/resources/simulation/sam-cfg.xml 2008-08-13 14:40:01 UTC (rev 242)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
+<ns2:processingNode name="DatabaseTestCase"
+ domain="http://org.jboss.sam/test/database"
+ xmlns:ns2="http://org.jboss.sam/08/2008/">
+
+ <properties/>
+
+ <database-references/>
+
+ <inputs/>
+
+ <outputs/>
+
+ <statements/>
+
+</ns2:processingNode>
\ No newline at end of file
Property changes on: sam/trunk/modules/sim/src/test/resources/simulation/sam-cfg.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
15 years, 9 months
Overlord SVN: r241 - in sam/trunk/modules: core/src/main/java/org/jboss/sam/config and 6 other directories.
by overlord-commits@lists.jboss.org
Author: heiko.braun(a)jboss.com
Date: 2008-08-13 08:54:02 -0400 (Wed, 13 Aug 2008)
New Revision: 241
Added:
sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntime.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntimeFactory.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DataSourceDef.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/DefaultRuntimeImpl.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DBCPDataSourceFactory.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DataSourceFactory.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DatasourceManager.java
Removed:
sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatasourceDef.java
Modified:
sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessorFactory.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ConfigFactory.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/config/Configurator.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatabaseRefDef.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsEventProcessorImpl.java
sam/trunk/modules/core/src/test/java/org/jboss/test/sam/SamTestSetup.java
sam/trunk/modules/core/src/test/java/org/jboss/test/sam/config/ConfigParserTestCase.java
sam/trunk/modules/sim/src/main/java/org/jboss/sam/simulation/EventSimulation.java
Log:
Revisit configuration and introduce notion of SAMRuntime
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessorFactory.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessorFactory.java 2008-08-13 11:56:07 UTC (rev 240)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessorFactory.java 2008-08-13 12:54:02 UTC (rev 241)
@@ -23,8 +23,6 @@
import org.jboss.sam.internal.drools.DroolsEventProcessorImpl;
-import java.net.URL;
-
/**
* @author Heiko.Braun <heiko.braun(a)jboss.com>
*/
@@ -39,14 +37,14 @@
return new DefaultEventProcessorFactory();
}
- public abstract EventProcessor createRuntime(String name, URL config);
+ public abstract EventProcessor createProcessor();
static class DefaultEventProcessorFactory extends EventProcessorFactory
{
- public EventProcessor createRuntime(String name, URL config)
+ public EventProcessor createProcessor()
{
- return new DroolsEventProcessorImpl(name, config);
+ return new DroolsEventProcessorImpl();
}
}
}
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntime.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntime.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntime.java 2008-08-13 12:54:02 UTC (rev 241)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam;
+
+import org.jboss.sam.config.Configurator;
+import org.jboss.sam.internal.datasource.DatasourceManager;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public abstract class SAMRuntime
+{
+ private Configurator configurator;
+
+ private EventProcessor eventProcessor;
+ private DatasourceManager datasourceManager;
+
+ protected SAMRuntime(Configurator configurator)
+ {
+ this.configurator = configurator;
+
+ // create and configure a processor
+ this.eventProcessor = EventProcessorFactory.newInstance().createProcessor();
+ configurator.configure(this.eventProcessor);
+
+ // create and configure datasources
+ this.datasourceManager = new DatasourceManager();
+ configurator.configure(datasourceManager);
+
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntime.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntimeFactory.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntimeFactory.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntimeFactory.java 2008-08-13 12:54:02 UTC (rev 241)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam;
+
+import org.jboss.sam.config.Configurator;
+import org.jboss.sam.internal.DefaultRuntimeImpl;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public abstract class SAMRuntimeFactory
+{
+
+ public abstract SAMRuntime createRuntime(Configurator configurator);
+
+ public static SAMRuntimeFactory newInstance()
+ {
+ return new DefaultRuntimeFactory();
+ }
+
+ static class DefaultRuntimeFactory extends SAMRuntimeFactory
+ {
+ public SAMRuntime createRuntime(Configurator configurator)
+ {
+ return new DefaultRuntimeImpl(configurator);
+ }
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/SAMRuntimeFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ConfigFactory.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ConfigFactory.java 2008-08-13 11:56:07 UTC (rev 240)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ConfigFactory.java 2008-08-13 12:54:02 UTC (rev 241)
@@ -40,6 +40,11 @@
*/
public class ConfigFactory
{
+
+ private ConfigFactory()
+ {
+ }
+
public static ConfigFactory newInstance()
{
return new ConfigFactory();
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/Configurator.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/config/Configurator.java 2008-08-13 11:56:07 UTC (rev 240)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/config/Configurator.java 2008-08-13 12:54:02 UTC (rev 241)
@@ -24,11 +24,16 @@
import org.jboss.sam.EventProcessor;
import org.jboss.sam.StreamInput;
import org.jboss.sam.StreamOutput;
+import org.jboss.sam.internal.datasource.DatasourceManager;
+import org.jboss.sam.internal.datasource.DataSourceFactory;
+import javax.sql.DataSource;
+
/**
- * An intermediary to configure {@link org.jboss.sam.EventProcessor}'s
- * from configuration descriptors. Allows for interception/modification
- * of configuration values.
+ * An intermediary to configure {@link org.jboss.sam.SAMRuntime}'s
+ * from configuration descriptors. <br>
+ * Allows for interception/modification of configuration values before the
+ * actuall configuration is applied to runtime components.
*
* @author Heiko.Braun <heiko.braun(a)jboss.com>
*/
@@ -83,6 +88,17 @@
}
}
+ public void configure(DatasourceManager manager)
+ {
+ DataSourceFactory dsFactory = DataSourceFactory.newInstance();
+
+ for(DatabaseRefDef def : this.nodeDef.getDatabases())
+ {
+ DataSource ds = dsFactory.createDataSource(def.getDatasource());
+ manager.addDataSource(def.getName(), ds);
+ }
+ }
+
private Object newInstance(String clazz)
{
Object obj = null;
Copied: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DataSourceDef.java (from rev 240, sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatasourceDef.java)
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DataSourceDef.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DataSourceDef.java 2008-08-13 12:54:02 UTC (rev 241)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.config;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+@XmlType(name = "dataSourceDefType")
+public class DataSourceDef
+{
+ private String name;
+ private String driver;
+ private String url;
+
+ private List<PropertyDef> connectionArgs = new ArrayList<PropertyDef>();
+
+
+ public DataSourceDef()
+ {
+ }
+
+ public DataSourceDef(String name, String driver, String url)
+ {
+ this.name = name;
+ this.driver = driver;
+ this.url = url;
+ }
+
+ @XmlAttribute
+ public String getUrl()
+ {
+ return url;
+ }
+
+ public void setUrl(String url)
+ {
+ this.url = url;
+ }
+
+ @XmlAttribute
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ @XmlAttribute
+ public String getDriver()
+ {
+ return driver;
+ }
+
+ public void setDriver(String driver)
+ {
+ this.driver = driver;
+ }
+
+ @XmlElement(name="connection-arg")
+ public List<PropertyDef> getConnectionArgs()
+ {
+ return connectionArgs;
+ }
+
+ public void setConnectionArgs(List<PropertyDef> connectionArgs)
+ {
+ this.connectionArgs = connectionArgs;
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DataSourceDef.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatabaseRefDef.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatabaseRefDef.java 2008-08-13 11:56:07 UTC (rev 240)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatabaseRefDef.java 2008-08-13 12:54:02 UTC (rev 241)
@@ -22,14 +22,16 @@
package org.jboss.sam.config;
import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
/**
* @author Heiko.Braun <heiko.braun(a)jboss.com>
*/
+@XmlType(name="databaseRefDefType")
public class DatabaseRefDef
{
private String name;
- private DatasourceDef datasource;
+ private DataSourceDef dataSource;
public DatabaseRefDef()
{
@@ -51,13 +53,13 @@
this.name = name;
}
- public DatasourceDef getDatasource()
+ public DataSourceDef getDatasource()
{
- return datasource;
+ return dataSource;
}
- public void setDatasource(DatasourceDef datasource)
+ public void setDatasource(DataSourceDef dataSource)
{
- this.datasource = datasource;
+ this.dataSource = dataSource;
}
}
Deleted: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatasourceDef.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatasourceDef.java 2008-08-13 11:56:07 UTC (rev 240)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatasourceDef.java 2008-08-13 12:54:02 UTC (rev 241)
@@ -1,95 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.sam.config;
-
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlAttribute;
-import java.util.List;
-import java.util.ArrayList;
-
-/**
- * @author Heiko.Braun <heiko.braun(a)jboss.com>
- */
-public class DatasourceDef
-{
- private String name;
- private String driver;
- private String url;
-
- private List<PropertyDef> connectionArgs = new ArrayList<PropertyDef>();
-
-
- public DatasourceDef()
- {
- }
-
- public DatasourceDef(String name, String driver, String url)
- {
- this.name = name;
- this.driver = driver;
- this.url = url;
- }
-
- @XmlAttribute
- public String getUrl()
- {
- return url;
- }
-
- public void setUrl(String url)
- {
- this.url = url;
- }
-
- @XmlAttribute
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
- @XmlAttribute
- public String getDriver()
- {
- return driver;
- }
-
- public void setDriver(String driver)
- {
- this.driver = driver;
- }
-
- @XmlElement(name="connection-arg")
- public List<PropertyDef> getConnectionArgs()
- {
- return connectionArgs;
- }
-
- public void setConnectionArgs(List<PropertyDef> connectionArgs)
- {
- this.connectionArgs = connectionArgs;
- }
-}
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/DefaultRuntimeImpl.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/DefaultRuntimeImpl.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/DefaultRuntimeImpl.java 2008-08-13 12:54:02 UTC (rev 241)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.internal;
+
+import org.jboss.sam.SAMRuntime;
+import org.jboss.sam.config.Configurator;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class DefaultRuntimeImpl extends SAMRuntime
+{
+
+ public DefaultRuntimeImpl(Configurator configurator)
+ {
+ super(configurator);
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/DefaultRuntimeImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DBCPDataSourceFactory.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DBCPDataSourceFactory.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DBCPDataSourceFactory.java 2008-08-13 12:54:02 UTC (rev 241)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.internal.datasource;
+
+import org.jboss.sam.config.DataSourceDef;
+import org.apache.commons.pool.ObjectPool;
+import org.apache.commons.pool.impl.GenericObjectPool;
+import org.apache.commons.dbcp.ConnectionFactory;
+import org.apache.commons.dbcp.DriverManagerConnectionFactory;
+import org.apache.commons.dbcp.PoolableConnectionFactory;
+import org.apache.commons.dbcp.PoolingDataSource;
+
+import javax.sql.DataSource;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class DBCPDataSourceFactory extends DataSourceFactory
+{
+
+ DBCPDataSourceFactory()
+ {
+ }
+
+ public DataSource createDataSource(DataSourceDef dsDef)
+ {
+ try {
+ Class.forName(dsDef.getDriver());
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException("Failed to load JDBC driver: " + dsDef.getDriver(), e);
+ }
+
+ //
+ // First, we'll need a ObjectPool that serves as the
+ // actual pool of connections.
+ //
+ // We'll use a GenericObjectPool instance, although
+ // any ObjectPool implementation will suffice.
+ //
+ ObjectPool connectionPool = new GenericObjectPool(null);
+
+ //
+ // Next, we'll create a ConnectionFactory that the
+ // pool will use to create Connections.
+ // We'll use the DriverManagerConnectionFactory,
+ // using the connect string passed in the command line
+ // arguments.
+ //
+ ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(dsDef.getUrl(),null);
+
+ //
+ // Now we'll create the PoolableConnectionFactory, which wraps
+ // the "real" Connections created by the ConnectionFactory with
+ // the classes that implement the pooling functionality.
+ //
+ PoolableConnectionFactory poolableConnectionFactory =
+ new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
+
+ //
+ // Finally, we create the PoolingDriver itself,
+ // passing in the object pool we created.
+ //
+ PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
+
+ return dataSource;
+
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DBCPDataSourceFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DataSourceFactory.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DataSourceFactory.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DataSourceFactory.java 2008-08-13 12:54:02 UTC (rev 241)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.internal.datasource;
+
+import org.jboss.sam.config.DataSourceDef;
+
+import javax.sql.DataSource;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public abstract class DataSourceFactory
+{
+ DataSourceFactory()
+ {
+ }
+
+ public static DataSourceFactory newInstance()
+ {
+ return new DBCPDataSourceFactory();
+ }
+
+ public abstract DataSource createDataSource(DataSourceDef dsDef);
+
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DataSourceFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DatasourceManager.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DatasourceManager.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DatasourceManager.java 2008-08-13 12:54:02 UTC (rev 241)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.internal.datasource;
+
+import javax.sql.DataSource;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class DatasourceManager
+{
+ private Map<String, DataSource> datasources = new ConcurrentHashMap<String, DataSource>();
+
+ public void addDataSource(String reference, DataSource ds)
+ {
+ if(datasources.containsKey(reference))
+ throw new IllegalArgumentException("DataSource '" + reference + "' does already exist!");
+
+ this.datasources.put(reference, ds);
+ }
+
+ public DataSource getDataSource(String reference)
+ {
+ DataSource ds = datasources.get(reference);
+ if(null==ds)
+ throw new IllegalArgumentException("No DataSource for reference '" + reference + "'");
+
+ return ds;
+ }
+
+ public boolean hasDataSource(String reference)
+ {
+ return datasources.containsKey(reference);
+ }
+
+
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/datasource/DatasourceManager.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsEventProcessorImpl.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsEventProcessorImpl.java 2008-08-13 11:56:07 UTC (rev 240)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsEventProcessorImpl.java 2008-08-13 12:54:02 UTC (rev 241)
@@ -31,11 +31,8 @@
import org.drools.lang.descr.PackageDescr;
import org.drools.spi.GlobalResolver;
import org.jboss.sam.*;
-import org.jboss.sam.config.ConfigFactory;
-import org.jboss.sam.config.Configurator;
import java.io.*;
-import java.net.URL;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
@@ -48,8 +45,7 @@
implements EventProcessor<RuleBase>, StreamInputCallback, GlobalResolver
{
- private String name;
- private URL config;
+ private String name;
private RuleBase ruleBase;
private StatefulSession session;
@@ -60,42 +56,28 @@
private Map<String, Object> wmGlobals = new ConcurrentHashMap<String, Object>();
private Map<String, StreamOutputAdapter> outputAdapters = new ConcurrentHashMap<String, StreamOutputAdapter>();
+
+ private final static String SAM_ADAPTER_NAME = "SAM";
- public DroolsEventProcessorImpl(String name, URL config)
+ public DroolsEventProcessorImpl()
{
- this.name = name;
- this.config = config;
-
try
{
-
this.ruleBase = RuleBaseFactory.newRuleBase( RuleBase.RETEOO, null );
this.session = ruleBase.newStatefulSession();
- this.session.setGlobalResolver(this);
-
- // parse config
- if(config!=null) applyConfiguration(config);
-
- } catch (Exception e)
+ this.session.setGlobalResolver(this);
+ }
+ catch (Exception e)
{
throw new RuntimeException("Failed to initialize event processor", e);
}
}
- private void applyConfiguration(URL config) throws Exception
- {
- ConfigFactory cfgFactory = ConfigFactory.newInstance();
- Configurator cfg = new Configurator( cfgFactory.unmarshall(config) );
- cfg.configure(this);
- }
-
-
public Object resolveGlobal(String key)
{
Object global = null;
-
- // TODO: Please note that there is also 'drools', revisit!
- if("SAM".equals(key))
+
+ if(SAM_ADAPTER_NAME.equals(key))
{
global = new SAMAdapter(this.session, this.outputAdapters);
}
Modified: sam/trunk/modules/core/src/test/java/org/jboss/test/sam/SamTestSetup.java
===================================================================
--- sam/trunk/modules/core/src/test/java/org/jboss/test/sam/SamTestSetup.java 2008-08-13 11:56:07 UTC (rev 240)
+++ sam/trunk/modules/core/src/test/java/org/jboss/test/sam/SamTestSetup.java 2008-08-13 12:54:02 UTC (rev 241)
@@ -25,13 +25,15 @@
import org.jboss.sam.EventProcessor;
import org.jboss.sam.EventProcessorFactory;
import org.jboss.sam.StreamInput;
+import org.jboss.sam.config.ConfigFactory;
+import org.jboss.sam.config.Configurator;
+import org.jboss.sam.internal.stream.InVMDispatcher;
import org.jboss.sam.internal.stream.InVMStreamInput;
-import org.jboss.sam.internal.stream.InVMDispatcher;
-import java.net.URL;
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.InputStreamReader;
-import java.io.IOException;
+import java.net.URL;
/**
* Basic SAM test skeleton. Test cases should derive from this class.
@@ -58,10 +60,16 @@
public void createProcessorWithDefaultIO(String name, String configFile)
{
// Main runtime
+ eventProcessor = EventProcessorFactory.newInstance().createProcessor();
+
URL config = configFile!=null ? loadTestConfiguration(configFile) : null;
- eventProcessor = EventProcessorFactory.newInstance().createRuntime(name, config);
+ if(config!=null)
+ {
+ Configurator configurator = new Configurator( ConfigFactory.newInstance().unmarshall(config) );
+ configurator.configure(eventProcessor);
+ }
- // Stream input and output
+ // Stream input and output
streamInput = new InVMStreamInput("InVM").start();
dispatcher = new InVMDispatcher(streamInput.getStreamName());
Modified: sam/trunk/modules/core/src/test/java/org/jboss/test/sam/config/ConfigParserTestCase.java
===================================================================
--- sam/trunk/modules/core/src/test/java/org/jboss/test/sam/config/ConfigParserTestCase.java 2008-08-13 11:56:07 UTC (rev 240)
+++ sam/trunk/modules/core/src/test/java/org/jboss/test/sam/config/ConfigParserTestCase.java 2008-08-13 12:54:02 UTC (rev 241)
@@ -76,7 +76,7 @@
// database references
DatabaseRefDef dbRef = new DatabaseRefDef("hsqlDB");
- DatasourceDef dsDef = new DatasourceDef("hsqlDS", "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:SamTestSetup");
+ DataSourceDef dsDef = new DataSourceDef("hsqlDS", "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:SamTestSetup");
dsDef.getConnectionArgs().add(new PropertyDef("user", "sa"));
dsDef.getConnectionArgs().add(new PropertyDef("password", ""));
dbRef.setDatasource(dsDef);
Modified: sam/trunk/modules/sim/src/main/java/org/jboss/sam/simulation/EventSimulation.java
===================================================================
--- sam/trunk/modules/sim/src/main/java/org/jboss/sam/simulation/EventSimulation.java 2008-08-13 11:56:07 UTC (rev 240)
+++ sam/trunk/modules/sim/src/main/java/org/jboss/sam/simulation/EventSimulation.java 2008-08-13 12:54:02 UTC (rev 241)
@@ -30,14 +30,14 @@
import org.jboss.sam.internal.stream.InVMDispatcher;
import org.jboss.sam.internal.stream.InVMStreamInput;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.UUID;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.IOException;
/**
* Simulations are created from global configuration,
@@ -88,7 +88,8 @@
this.context = new SimulationContext(config);
// setup SAM processor
- this.eventProcessor = EventProcessorFactory.newInstance().createRuntime( "EventSimulation", bootstrap );
+ this.eventProcessor = EventProcessorFactory.newInstance().createProcessor();
+ this.eventProcessor.setName("EventSimulation");
// create input for the default in-vm channel
this.streamInput = new InVMStreamInput(InVMDispatcher.DEFAULT_CHANNEL_NAME);
15 years, 9 months
Overlord SVN: r240 - in sam/trunk: modules/core and 3 other directories.
by overlord-commits@lists.jboss.org
Author: heiko.braun(a)jboss.com
Date: 2008-08-13 07:56:07 -0400 (Wed, 13 Aug 2008)
New Revision: 240
Added:
sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ConfigurationDef.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatabaseRefDef.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatasourceDef.java
Removed:
sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ProcessingNodeDef.java
Modified:
sam/trunk/modules/core/pom.xml
sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ConfigFactory.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/config/Configurator.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/config/PropertyDef.java
sam/trunk/modules/core/src/test/java/org/jboss/test/sam/config/ConfigParserTestCase.java
sam/trunk/modules/core/src/test/resources/database/test.drl
sam/trunk/pom.xml
sam/trunk/sam-trunk.iml
Log:
Added datasource config element
Modified: sam/trunk/modules/core/pom.xml
===================================================================
--- sam/trunk/modules/core/pom.xml 2008-08-13 09:39:31 UTC (rev 239)
+++ sam/trunk/modules/core/pom.xml 2008-08-13 11:56:07 UTC (rev 240)
@@ -33,6 +33,10 @@
<artifactId>drools-compiler</artifactId>
</dependency>
+ <dependency>
+ <groupId>commons-dbcp</groupId>
+ <artifactId>commons-dbcp</artifactId>
+ </dependency>
<dependency>
<groupId>junit</groupId>
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ConfigFactory.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ConfigFactory.java 2008-08-13 09:39:31 UTC (rev 239)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ConfigFactory.java 2008-08-13 11:56:07 UTC (rev 240)
@@ -45,7 +45,7 @@
return new ConfigFactory();
}
- public ProcessingNodeDef unmarshall(URL configFile)
+ public ConfigurationDef unmarshall(URL configFile)
{
try
{
@@ -57,15 +57,15 @@
}
}
- public ProcessingNodeDef unmarshall(InputStream inputStream)
+ public ConfigurationDef unmarshall(InputStream inputStream)
{
- ProcessingNodeDef pnd = null;
+ ConfigurationDef pnd = null;
try
{
- JAXBContext jaxb = JAXBContext.newInstance(ProcessingNodeDef.class);
+ JAXBContext jaxb = JAXBContext.newInstance(ConfigurationDef.class);
Unmarshaller unmarshaller = jaxb.createUnmarshaller();
- pnd = (ProcessingNodeDef) unmarshaller.unmarshal(inputStream);
+ pnd = (ConfigurationDef) unmarshaller.unmarshal(inputStream);
} catch (Exception e)
{
@@ -87,11 +87,11 @@
}
- public void marshall(ProcessingNodeDef pnd, OutputStream out)
+ public void marshall(ConfigurationDef pnd, OutputStream out)
{
try
{
- JAXBContext jaxb = JAXBContext.newInstance(ProcessingNodeDef.class);
+ JAXBContext jaxb = JAXBContext.newInstance(ConfigurationDef.class);
Marshaller marshaller = jaxb.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
// encoding needs to be different to UTF-8, otherwise the custom encode will not be used
Copied: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ConfigurationDef.java (from rev 231, sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ProcessingNodeDef.java)
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ConfigurationDef.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ConfigurationDef.java 2008-08-13 11:56:07 UTC (rev 240)
@@ -0,0 +1,147 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.config;
+
+import javax.xml.bind.annotation.*;
+import java.net.URI;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+@XmlRootElement(name = "processingNode", namespace = "http://org.jboss.sam/08/2008/")
+@XmlType(
+ name = "processingNodeType",
+ namespace = "http://org.jboss.sam/08/2008/",
+ propOrder = {
+ "props", "databases", "inputs", "outputs", "statements"
+ }
+)
+public class ConfigurationDef
+{
+
+ private String name;
+ private URI domain;
+
+ private List<StatementDef> statements = new ArrayList<StatementDef>();
+
+ private List<StreamInputDef> inputs = new ArrayList<StreamInputDef>();
+
+ private List<StreamOutputDef> outputs = new ArrayList<StreamOutputDef>();
+
+ private List<PropertyDef> props = new ArrayList<PropertyDef>();
+
+ private List<DatabaseRefDef> databases = new ArrayList<DatabaseRefDef>();
+
+ public ConfigurationDef()
+ {
+ }
+
+ public ConfigurationDef(String name, URI domain)
+ {
+ this.name = name;
+ this.domain = domain;
+ }
+
+ @XmlAttribute
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ @XmlAttribute
+ public URI getDomain()
+ {
+ return domain;
+ }
+
+ public void setDomain(URI domain)
+ {
+ this.domain = domain;
+ }
+
+ @XmlElementWrapper(name = "statements")
+ @XmlElement(name="statement")
+ public List<StatementDef> getStatements()
+ {
+ return statements;
+ }
+
+ public void setStatements(List<StatementDef> statements)
+ {
+ this.statements = statements;
+ }
+
+ @XmlElementWrapper(name = "inputs")
+ @XmlElement(name="input")
+ public List<StreamInputDef> getInputs()
+ {
+ return inputs;
+ }
+
+ public void setInputs(List<StreamInputDef> inputs)
+ {
+ this.inputs = inputs;
+ }
+
+ @XmlElementWrapper(name = "outputs")
+ @XmlElement(name="output")
+ public List<StreamOutputDef> getOutputs()
+ {
+ return outputs;
+ }
+
+ public void setOutputs(List<StreamOutputDef> outputs)
+ {
+ this.outputs = outputs;
+ }
+
+ @XmlElementWrapper(name = "properties")
+ @XmlElement(name="property")
+ public List<PropertyDef> getProps()
+ {
+ return props;
+ }
+
+ public void setProps(List<PropertyDef> props)
+ {
+ this.props = props;
+ }
+
+ @XmlElementWrapper(name = "database-references")
+ @XmlElement(name="database-reference")
+ public List<DatabaseRefDef> getDatabases()
+ {
+ return databases;
+ }
+
+ public void setDatabases(List<DatabaseRefDef> databases)
+ {
+ this.databases = databases;
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ConfigurationDef.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/Configurator.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/config/Configurator.java 2008-08-13 09:39:31 UTC (rev 239)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/config/Configurator.java 2008-08-13 11:56:07 UTC (rev 240)
@@ -35,15 +35,15 @@
public class Configurator
{
private ClassLoader loader = Thread.currentThread().getContextClassLoader();
- private ProcessingNodeDef nodeDef;
+ private ConfigurationDef nodeDef;
- public Configurator(ProcessingNodeDef nodeDef, ClassLoader loader)
+ public Configurator(ConfigurationDef nodeDef, ClassLoader loader)
{
this.nodeDef = nodeDef;
this.loader = loader;
}
- public Configurator(ProcessingNodeDef nodeDef)
+ public Configurator(ConfigurationDef nodeDef)
{
this.nodeDef = nodeDef;
}
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatabaseRefDef.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatabaseRefDef.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatabaseRefDef.java 2008-08-13 11:56:07 UTC (rev 240)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.config;
+
+import javax.xml.bind.annotation.XmlAttribute;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class DatabaseRefDef
+{
+ private String name;
+ private DatasourceDef datasource;
+
+ public DatabaseRefDef()
+ {
+ }
+
+ public DatabaseRefDef(String name)
+ {
+ this.name = name;
+ }
+
+ @XmlAttribute
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public DatasourceDef getDatasource()
+ {
+ return datasource;
+ }
+
+ public void setDatasource(DatasourceDef datasource)
+ {
+ this.datasource = datasource;
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatabaseRefDef.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatasourceDef.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatasourceDef.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatasourceDef.java 2008-08-13 11:56:07 UTC (rev 240)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.config;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlAttribute;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class DatasourceDef
+{
+ private String name;
+ private String driver;
+ private String url;
+
+ private List<PropertyDef> connectionArgs = new ArrayList<PropertyDef>();
+
+
+ public DatasourceDef()
+ {
+ }
+
+ public DatasourceDef(String name, String driver, String url)
+ {
+ this.name = name;
+ this.driver = driver;
+ this.url = url;
+ }
+
+ @XmlAttribute
+ public String getUrl()
+ {
+ return url;
+ }
+
+ public void setUrl(String url)
+ {
+ this.url = url;
+ }
+
+ @XmlAttribute
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ @XmlAttribute
+ public String getDriver()
+ {
+ return driver;
+ }
+
+ public void setDriver(String driver)
+ {
+ this.driver = driver;
+ }
+
+ @XmlElement(name="connection-arg")
+ public List<PropertyDef> getConnectionArgs()
+ {
+ return connectionArgs;
+ }
+
+ public void setConnectionArgs(List<PropertyDef> connectionArgs)
+ {
+ this.connectionArgs = connectionArgs;
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/DatasourceDef.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Deleted: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ProcessingNodeDef.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ProcessingNodeDef.java 2008-08-13 09:39:31 UTC (rev 239)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/config/ProcessingNodeDef.java 2008-08-13 11:56:07 UTC (rev 240)
@@ -1,134 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.sam.config;
-
-import javax.xml.bind.annotation.*;
-import java.net.URI;
-import java.util.List;
-import java.util.ArrayList;
-
-/**
- * @author Heiko.Braun <heiko.braun(a)jboss.com>
- */
-@XmlRootElement(name = "processingNode", namespace = "http://org.jboss.sam/08/2008/")
-@XmlType(
- name = "processingNodeType",
- namespace = "http://org.jboss.sam/08/2008/",
- propOrder = {
- "props", "inputs", "outputs", "statements"
- }
-)
-public class ProcessingNodeDef
-{
-
- private String name;
- private URI domain;
-
- private List<StatementDef> statements = new ArrayList<StatementDef>();
-
- private List<StreamInputDef> inputs = new ArrayList<StreamInputDef>();
-
- private List<StreamOutputDef> outputs = new ArrayList<StreamOutputDef>();
-
- private List<PropertyDef> props = new ArrayList<PropertyDef>();
-
-
- public ProcessingNodeDef()
- {
- }
-
- public ProcessingNodeDef(String name, URI domain)
- {
- this.name = name;
- this.domain = domain;
- }
-
- @XmlAttribute
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
- @XmlAttribute
- public URI getDomain()
- {
- return domain;
- }
-
- public void setDomain(URI domain)
- {
- this.domain = domain;
- }
-
- @XmlElementWrapper(name = "statements")
- @XmlElement(name="statement")
- public List<StatementDef> getStatements()
- {
- return statements;
- }
-
- public void setStatements(List<StatementDef> statements)
- {
- this.statements = statements;
- }
-
- @XmlElementWrapper(name = "inputs")
- @XmlElement(name="input")
- public List<StreamInputDef> getInputs()
- {
- return inputs;
- }
-
- public void setInputs(List<StreamInputDef> inputs)
- {
- this.inputs = inputs;
- }
-
- @XmlElementWrapper(name = "outputs")
- @XmlElement(name="output")
- public List<StreamOutputDef> getOutputs()
- {
- return outputs;
- }
-
- public void setOutputs(List<StreamOutputDef> outputs)
- {
- this.outputs = outputs;
- }
-
- @XmlElementWrapper(name = "properties")
- @XmlElement(name="property")
- public List<PropertyDef> getProps()
- {
- return props;
- }
-
- public void setProps(List<PropertyDef> props)
- {
- this.props = props;
- }
-}
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/config/PropertyDef.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/config/PropertyDef.java 2008-08-13 09:39:31 UTC (rev 239)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/config/PropertyDef.java 2008-08-13 11:56:07 UTC (rev 240)
@@ -21,21 +21,33 @@
*/
package org.jboss.sam.config;
+import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
/**
* @author Heiko.Braun <heiko.braun(a)jboss.com>
*/
-@XmlType(name = "propertyDefType")
+@XmlType(
+ name = "propertyDefType",
+ propOrder = {"name", "value"}
+)
public class PropertyDef
{
private String name;
private String value;
+
public PropertyDef()
{
}
+ public PropertyDef(String name, String value)
+ {
+ this.name = name;
+ this.value = value;
+ }
+
+ @XmlAttribute
public String getName()
{
return name;
@@ -46,6 +58,7 @@
this.name = name;
}
+ @XmlAttribute
public String getValue()
{
return value;
Modified: sam/trunk/modules/core/src/test/java/org/jboss/test/sam/config/ConfigParserTestCase.java
===================================================================
--- sam/trunk/modules/core/src/test/java/org/jboss/test/sam/config/ConfigParserTestCase.java 2008-08-13 09:39:31 UTC (rev 239)
+++ sam/trunk/modules/core/src/test/java/org/jboss/test/sam/config/ConfigParserTestCase.java 2008-08-13 11:56:07 UTC (rev 240)
@@ -46,7 +46,7 @@
public void testMarshalling() throws Exception
{
- ProcessingNodeDef pnd = new ProcessingNodeDef("BPMEventProcessor", new URI("http://org.jboss.bpm/console"));
+ ConfigurationDef pnd = new ConfigurationDef("BPMEventProcessor", new URI("http://org.jboss.bpm/console"));
// define stream input and outputs
pnd.getInputs().add( new StreamInputDef("VMInput", InVMStreamInput.class.getName()) );
@@ -58,13 +58,13 @@
"package org.jboss.test.sam.drools;\n" +
"\n" +
"import org.jboss.test.sam.drools.StockTick;\n" +
- "global org.jboss.sam.internal.drools.DroolsAdapter Drools;\n" +
+ "global org.jboss.sam.internal.drools.SAMAdapter SAM;\n" +
"\n" +
"rule \"Check event\"\n" +
"when\n" +
" $st: StockTick(symbol == \"ACME\")\n" +
"then\n" +
- " Drools.getListener(\"VMOutput\").update($st);\n" +
+ " SAM.getListener(\"VMOutput\").update($st);\n" +
"end"
);
@@ -74,6 +74,14 @@
pnd.getStatements().add(stmtmDef);
+ // database references
+ DatabaseRefDef dbRef = new DatabaseRefDef("hsqlDB");
+ DatasourceDef dsDef = new DatasourceDef("hsqlDS", "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:SamTestSetup");
+ dsDef.getConnectionArgs().add(new PropertyDef("user", "sa"));
+ dsDef.getConnectionArgs().add(new PropertyDef("password", ""));
+ dbRef.setDatasource(dsDef);
+ pnd.getDatabases().add(dbRef);
+
// marshall it
ByteArrayOutputStream bout = new ByteArrayOutputStream();
cfgFactory.marshall(pnd, bout);
@@ -86,7 +94,7 @@
{
System.out.println("Config:\n" + new String(XML_CONFIG));
- ProcessingNodeDef pnd = cfgFactory.unmarshall( new ByteArrayInputStream(XML_CONFIG));
+ ConfigurationDef pnd = cfgFactory.unmarshall( new ByteArrayInputStream(XML_CONFIG));
assertNotNull("ProcessingNodeDef not unmarshalled", pnd);
assertEquals("BPMEventProcessor", pnd.getName());
Modified: sam/trunk/modules/core/src/test/resources/database/test.drl
===================================================================
--- sam/trunk/modules/core/src/test/resources/database/test.drl 2008-08-13 09:39:31 UTC (rev 239)
+++ sam/trunk/modules/core/src/test/resources/database/test.drl 2008-08-13 11:56:07 UTC (rev 240)
@@ -8,9 +8,8 @@
when
$query: Query();
$sqlStream: ArrayList() from collect (
- String() from SAM.executeSQL("hsqlDB", "SELECT * FROM StockQuotes WHERE symbol=$query.criteria")
+ String() from SAM.executeSQL("hsqlDB", "SELECT * FROM StockQuotes WHERE symbol='"+$query.criteria+"'")
);
then
- System.out.println("Query is: " + $query.criteria);
SAM.getListener("InVM").update($sqlStream);
end
\ No newline at end of file
Modified: sam/trunk/pom.xml
===================================================================
--- sam/trunk/pom.xml 2008-08-13 09:39:31 UTC (rev 239)
+++ sam/trunk/pom.xml 2008-08-13 11:56:07 UTC (rev 240)
@@ -21,6 +21,7 @@
<surefire.security.args>-Djava.security.manager -Djava.security.policy=src/test/etc/tst.policy</surefire.security.args>
<surefire.jdwp.args>-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005</surefire.jdwp.args>
+ <dbcp.version>1.2.2</dbcp.version>
<drools.version>5.0.0.SNAPSHOT</drools.version>
<junit.version>3.8.2</junit.version>
<commons-logging.version>1.1</commons-logging.version>
@@ -51,6 +52,12 @@
</dependency>
<dependency>
+ <groupId>commons-dbcp</groupId>
+ <artifactId>commons-dbcp</artifactId>
+ <version>${dbcp.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
Modified: sam/trunk/sam-trunk.iml
===================================================================
--- sam/trunk/sam-trunk.iml 2008-08-13 09:39:31 UTC (rev 239)
+++ sam/trunk/sam-trunk.iml 2008-08-13 11:56:07 UTC (rev 240)
@@ -171,6 +171,24 @@
<SOURCES />
</library>
</orderEntry>
+ <orderEntry type="module-library">
+ <library name="M2 Dep: commons-pool:commons-pool:jar:1.3:compile">
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/../../../../.m2/repository/commons-pool/commons-pool/1.3/commons-pool-1.3.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library name="M2 Dep: commons-dbcp:commons-dbcp:jar:1.2.2:compile">
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/../../../../.m2/repository/commons-dbcp/commons-dbcp/1.2.2/commons-dbcp-1.2.2.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
<orderEntryProperties />
</component>
<component name="VcsManagerConfiguration">
15 years, 9 months
Overlord SVN: r239 - in sam/trunk: modules/core/src/main/java/org/jboss/sam/internal/drools and 8 other directories.
by overlord-commits@lists.jboss.org
Author: heiko.braun(a)jboss.com
Date: 2008-08-13 05:39:31 -0400 (Wed, 13 Aug 2008)
New Revision: 239
Added:
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/SAMAdapter.java
sam/trunk/modules/core/src/test/resources/adapter/invm/sam-cfg.xml
sam/trunk/modules/core/src/test/resources/database/test.drl
Removed:
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsAdapter.java
sam/trunk/modules/core/src/test/resources/adapter/invm/test.drl
Modified:
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsEventProcessorImpl.java
sam/trunk/modules/core/src/test/java/org/jboss/test/sam/SamTestSetup.java
sam/trunk/modules/core/src/test/java/org/jboss/test/sam/adapter/invm/InVMAdapterTestCase.java
sam/trunk/modules/core/src/test/java/org/jboss/test/sam/database/DatabaseTestCase.java
sam/trunk/modules/core/src/test/resources/database/sam-cfg.xml
sam/trunk/modules/core/src/test/resources/drools/aggregate.drl
sam/trunk/modules/core/src/test/resources/drools/forward.drl
sam/trunk/modules/core/src/test/resources/drools/simple.drl
sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/BufferedStreamOutput.java
sam/trunk/modules/sim/src/test/resources/simulation/test.drl
sam/trunk/sam-trunk.iml
Log:
Introduce global SAMAdapter->'SAM', that bridges into SAM extension points
Deleted: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsAdapter.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsAdapter.java 2008-08-13 08:56:17 UTC (rev 238)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsAdapter.java 2008-08-13 09:39:31 UTC (rev 239)
@@ -1,62 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.sam.internal.drools;
-
-import org.drools.StatefulSession;
-import org.drools.WorkingMemoryEntryPoint;
-
-import java.util.Map;
-
-/**
- * Will be injected into WorkingMemory to give access drools entities that
- * are relevant to the SAM processing model.
- *
- * @author Heiko.Braun <heiko.braun(a)jboss.com>
- */
-public class DroolsAdapter
-{
- private StatefulSession session;
- private Map<String, StreamOutputAdapter> outputAdapters;
-
- public DroolsAdapter(StatefulSession session, Map<String, StreamOutputAdapter> outputAdapters)
- {
- this.session = session;
- this.outputAdapters = outputAdapters;
- }
-
- public WorkingMemoryEntryPoint getStream(String name)
- {
- WorkingMemoryEntryPoint memoryEntryPoint = this.session.getWorkingMemoryEntryPoint(name);
- if(null==memoryEntryPoint)
- throw new IllegalArgumentException("Unknown stream " + name);
-
- return memoryEntryPoint;
- }
-
- public UpdateListener getListener(String name)
- {
- StreamOutputAdapter adapter = this.outputAdapters.get(name);
- if(null==adapter)
- throw new IllegalArgumentException("Unknown listener '" + name +"'");
- return adapter;
- }
-}
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsEventProcessorImpl.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsEventProcessorImpl.java 2008-08-13 08:56:17 UTC (rev 238)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsEventProcessorImpl.java 2008-08-13 09:39:31 UTC (rev 239)
@@ -95,9 +95,9 @@
Object global = null;
// TODO: Please note that there is also 'drools', revisit!
- if("Drools".equals(key))
+ if("SAM".equals(key))
{
- global = new DroolsAdapter(this.session, this.outputAdapters);
+ global = new SAMAdapter(this.session, this.outputAdapters);
}
else
{
Copied: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/SAMAdapter.java (from rev 196, sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/DroolsAdapter.java)
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/SAMAdapter.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/SAMAdapter.java 2008-08-13 09:39:31 UTC (rev 239)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.internal.drools;
+
+import org.drools.StatefulSession;
+import org.drools.WorkingMemoryEntryPoint;
+
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Will be injected into WorkingMemory to give access drools entities that
+ * are relevant to the SAM processing model. This class basically acts as a workaround for
+ * features that we would like to see:
+ *
+ * <ul>
+ * <li>Hidden behind a custom SAM DSL
+ * <li>or provided by Drools Fusion directly (JIRA)
+ * </ul>
+ *
+ * @author Heiko.Braun <heiko.braun(a)jboss.com>
+ */
+public class SAMAdapter
+{
+ private StatefulSession session;
+ private Map<String, StreamOutputAdapter> outputAdapters;
+
+ public SAMAdapter(StatefulSession session, Map<String, StreamOutputAdapter> outputAdapters)
+ {
+ this.session = session;
+ this.outputAdapters = outputAdapters;
+ }
+
+ public WorkingMemoryEntryPoint getStream(String name)
+ {
+ WorkingMemoryEntryPoint memoryEntryPoint = this.session.getWorkingMemoryEntryPoint(name);
+ if(null==memoryEntryPoint)
+ throw new IllegalArgumentException("Unknown stream " + name);
+
+ return memoryEntryPoint;
+ }
+
+ public UpdateListener getListener(String name)
+ {
+ StreamOutputAdapter adapter = this.outputAdapters.get(name);
+ if(null==adapter)
+ throw new IllegalArgumentException("Unknown listener '" + name +"'");
+ return adapter;
+ }
+
+ public List executeSQL(String dbName, String sql)
+ {
+ System.out.println("SQL: " + sql);
+ ArrayList results = new ArrayList();
+ results.add("Hello");
+ results.add("World");
+ return results;
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/SAMAdapter.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: sam/trunk/modules/core/src/test/java/org/jboss/test/sam/SamTestSetup.java
===================================================================
--- sam/trunk/modules/core/src/test/java/org/jboss/test/sam/SamTestSetup.java 2008-08-13 08:56:17 UTC (rev 238)
+++ sam/trunk/modules/core/src/test/java/org/jboss/test/sam/SamTestSetup.java 2008-08-13 09:39:31 UTC (rev 239)
@@ -64,10 +64,10 @@
// Stream input and output
streamInput = new InVMStreamInput("InVM").start();
dispatcher = new InVMDispatcher(streamInput.getStreamName());
-
+
bufferedOutput = new BufferedStreamOutput("InVM").start();
eventProcessor.addInput(streamInput);
- eventProcessor.addOutput(bufferedOutput);
+ eventProcessor.addOutput(bufferedOutput);
}
/**
Modified: sam/trunk/modules/core/src/test/java/org/jboss/test/sam/adapter/invm/InVMAdapterTestCase.java
===================================================================
--- sam/trunk/modules/core/src/test/java/org/jboss/test/sam/adapter/invm/InVMAdapterTestCase.java 2008-08-13 08:56:17 UTC (rev 238)
+++ sam/trunk/modules/core/src/test/java/org/jboss/test/sam/adapter/invm/InVMAdapterTestCase.java 2008-08-13 09:39:31 UTC (rev 239)
@@ -31,15 +31,11 @@
{
public void setUp()
{
- createProcessorWithDefaultIO("InVMAdapterTestCase", null);
+ createProcessorWithDefaultIO("InVMAdapterTestCase", "adapter/invm/sam-cfg.xml");
}
public void testAdapter() throws Exception
- {
- // setup
- String stmt = getDRLFromResource("adapter/invm/test.drl");
- ProcessingStatement view = eventProcessor.registerBoundStatement("InVM","AlertTest", stmt);
-
+ {
// fire event
generateInVMEvent( new Alert("sensor1", "Threshold exceeded") );
Modified: sam/trunk/modules/core/src/test/java/org/jboss/test/sam/database/DatabaseTestCase.java
===================================================================
--- sam/trunk/modules/core/src/test/java/org/jboss/test/sam/database/DatabaseTestCase.java 2008-08-13 08:56:17 UTC (rev 238)
+++ sam/trunk/modules/core/src/test/java/org/jboss/test/sam/database/DatabaseTestCase.java 2008-08-13 09:39:31 UTC (rev 239)
@@ -61,7 +61,7 @@
db.update("INSERT INTO quotes (symbol, name, price) VALUES('GOOG', 'Goole', 572.51)");
// database dump
- db.query("SELECT symbol, price FROM quotes");
+ //db.query("SELECT symbol, price FROM quotes");
}
protected void tearDown() throws Exception
@@ -75,10 +75,9 @@
public void testTriggeredSQLQuery() throws Exception
{
// setup
- /*String epl = "select symbol, price from Query.win:length(1) as query," +
- " sql:SamTestDB ['SELECT symbol, price FROM quotes WHERE symbol like (${query.criteria})']";
+ String epl = getDRLFromResource("database/test.drl");
- eventProcessor.registerBoundStatement("InVM","TriggerSQL", epl);
+ eventProcessor.registerBoundStatement("InVM","PullSQL", epl);
// trigger
generateInVMEvent( new Query("%") );
@@ -86,17 +85,16 @@
// evaluate
assertTrue("Listener not invoked", bufferedOutput.isInvoked());
EventMessage[] eventMessages = bufferedOutput.getLastNewData();
- assertTrue(eventMessages.length==7);
for(EventMessage event : eventMessages)
{
- System.out.println("symbol/price -> " + event.getProperty("symbol") + "/" + event.getProperty("price"));
- } */
+ System.out.println("!! " + event.getUnderlying() );
+ }
}
public void testEsperPullAPI() throws Exception
{
- System.out.println("FIXME ESPER-254: testPullAPI on database queries");
+ System.out.println("FIXME: testPullAPI on database queries");
/*See http://jira.codehaus.org/browse/ESPER-254
Added: sam/trunk/modules/core/src/test/resources/adapter/invm/sam-cfg.xml
===================================================================
--- sam/trunk/modules/core/src/test/resources/adapter/invm/sam-cfg.xml (rev 0)
+++ sam/trunk/modules/core/src/test/resources/adapter/invm/sam-cfg.xml 2008-08-13 09:39:31 UTC (rev 239)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
+<ns2:processingNode name="InVMAdapterTestCase"
+ domain="http://org.jboss.sam/test/database"
+ xmlns:ns2="http://org.jboss.sam/08/2008/">
+ <statements>
+ <statement name="ExampleStatement" bindTo="VMOutput">
+ <epl lang="drl"><![CDATA[
+package org.jboss.test.sam.drools;
+
+ import org.jboss.test.sam.adapter.invm.Alert;
+ global org.jboss.sam.internal.drools.SAMAdapter SAM;
+
+ rule "Select any Alert"
+ when
+ $event: Alert()
+ then
+ SAM.getListener("InVM").update($event);
+ end
+ ]]></epl>
+ </statement>
+ </statements>
+</ns2:processingNode>
\ No newline at end of file
Property changes on: sam/trunk/modules/core/src/test/resources/adapter/invm/sam-cfg.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Deleted: sam/trunk/modules/core/src/test/resources/adapter/invm/test.drl
===================================================================
--- sam/trunk/modules/core/src/test/resources/adapter/invm/test.drl 2008-08-13 08:56:17 UTC (rev 238)
+++ sam/trunk/modules/core/src/test/resources/adapter/invm/test.drl 2008-08-13 09:39:31 UTC (rev 239)
@@ -1,11 +0,0 @@
-package org.jboss.test.sam.drools;
-
-import org.jboss.test.sam.adapter.invm.Alert;
-global org.jboss.sam.internal.drools.DroolsAdapter Drools;
-
-rule "Select any Alert"
-when
- $event: Alert()
-then
- Drools.getListener("InVM").update($event);
-end
Modified: sam/trunk/modules/core/src/test/resources/database/sam-cfg.xml
===================================================================
--- sam/trunk/modules/core/src/test/resources/database/sam-cfg.xml 2008-08-13 08:56:17 UTC (rev 238)
+++ sam/trunk/modules/core/src/test/resources/database/sam-cfg.xml 2008-08-13 09:39:31 UTC (rev 239)
@@ -2,28 +2,7 @@
<ns2:processingNode name="DatabaseTestCase"
domain="http://org.jboss.sam/test/database"
xmlns:ns2="http://org.jboss.sam/08/2008/">
- <config/>
- <inputs>
- <input name="VMInput" clazz="org.jboss.sam.internal.stream.InVMStreamInput"/>
- </inputs>
- <outputs>
- <output name="VMOutput" clazz="org.jboss.test.sam.BufferedStreamOutput"/>
- </outputs>
- <statements>
- <statement name="ExampleStatement">
- <epl lang="drl"><![CDATA[
-package org.jboss.test.sam.drools;
-import org.jboss.test.sam.drools.StockTick;
-global org.jboss.sam.internal.drools.DroolsAdapter Drools;
-
-rule "Check event"
-when
- $st: StockTick(symbol == "ACME")
-then
- Drools.getListener("InVM").update($st);
-end
-]]></epl>
- </statement>
- </statements>
+ <statements/>
+
</ns2:processingNode>
\ No newline at end of file
Added: sam/trunk/modules/core/src/test/resources/database/test.drl
===================================================================
--- sam/trunk/modules/core/src/test/resources/database/test.drl (rev 0)
+++ sam/trunk/modules/core/src/test/resources/database/test.drl 2008-08-13 09:39:31 UTC (rev 239)
@@ -0,0 +1,16 @@
+package org.jboss.test.sam.database;
+
+import java.util.ArrayList;
+
+global org.jboss.sam.internal.drools.SAMAdapter SAM;
+
+rule "Simple SQL pull"
+when
+ $query: Query();
+ $sqlStream: ArrayList() from collect (
+ String() from SAM.executeSQL("hsqlDB", "SELECT * FROM StockQuotes WHERE symbol=$query.criteria")
+ );
+then
+ System.out.println("Query is: " + $query.criteria);
+ SAM.getListener("InVM").update($sqlStream);
+end
\ No newline at end of file
Modified: sam/trunk/modules/core/src/test/resources/drools/aggregate.drl
===================================================================
--- sam/trunk/modules/core/src/test/resources/drools/aggregate.drl 2008-08-13 08:56:17 UTC (rev 238)
+++ sam/trunk/modules/core/src/test/resources/drools/aggregate.drl 2008-08-13 09:39:31 UTC (rev 239)
@@ -2,11 +2,11 @@
import org.jboss.test.sam.drools.StockTick;
-global org.jboss.sam.internal.drools.DroolsAdapter Drools;
+global org.jboss.sam.internal.drools.SAMAdapter SAM;
rule "Aggregate any stock tick into AllTicks"
when
$event: StockTick();
then
- Drools.getStream("AllTicks").insert($event);
+ SAM.getStream("AllTicks").insert($event);
end
Modified: sam/trunk/modules/core/src/test/resources/drools/forward.drl
===================================================================
--- sam/trunk/modules/core/src/test/resources/drools/forward.drl 2008-08-13 08:56:17 UTC (rev 238)
+++ sam/trunk/modules/core/src/test/resources/drools/forward.drl 2008-08-13 09:39:31 UTC (rev 239)
@@ -2,11 +2,11 @@
import org.jboss.test.sam.drools.StockTick;
-global org.jboss.sam.internal.drools.DroolsAdapter Drools;
+global org.jboss.sam.internal.drools.SAMAdapter SAM;
rule "Forward all stock ticks to listener"
when
$event: StockTick() from entry-point "AllTicks";
then
- Drools.getListener("InVM").update($event);
+ SAM.getListener("InVM").update($event);
end
Modified: sam/trunk/modules/core/src/test/resources/drools/simple.drl
===================================================================
--- sam/trunk/modules/core/src/test/resources/drools/simple.drl 2008-08-13 08:56:17 UTC (rev 238)
+++ sam/trunk/modules/core/src/test/resources/drools/simple.drl 2008-08-13 09:39:31 UTC (rev 239)
@@ -1,11 +1,11 @@
package org.jboss.test.sam.drools;
import org.jboss.test.sam.drools.StockTick;
-global org.jboss.sam.internal.drools.DroolsAdapter Drools;
+global org.jboss.sam.internal.drools.SAMAdapter SAM;
rule "Check event"
when
$st: StockTick(symbol == "ACME")
then
- Drools.getListener("InVM").update($st);
+ SAM.getListener("InVM").update($st);
end
Modified: sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/BufferedStreamOutput.java
===================================================================
--- sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/BufferedStreamOutput.java 2008-08-13 08:56:17 UTC (rev 238)
+++ sam/trunk/modules/sim/src/test/java/org/jboss/test/sam/BufferedStreamOutput.java 2008-08-13 09:39:31 UTC (rev 239)
@@ -82,8 +82,14 @@
public String getStreamName()
{
return this.streamName;
- }
+ }
+
+ public void setStreamName(String name)
+ {
+ this.streamName = name;
+ }
+
public void write(EventMessage[] args)
{
update(args, new EventMessage[]{});
Modified: sam/trunk/modules/sim/src/test/resources/simulation/test.drl
===================================================================
--- sam/trunk/modules/sim/src/test/resources/simulation/test.drl 2008-08-13 08:56:17 UTC (rev 238)
+++ sam/trunk/modules/sim/src/test/resources/simulation/test.drl 2008-08-13 09:39:31 UTC (rev 239)
@@ -2,11 +2,11 @@
import org.jboss.test.sam.simulation.SensorEventMessage;
-global org.jboss.sam.internal.drools.DroolsAdapter Drools;
+global org.jboss.sam.internal.drools.SAMAdapter SAM;
rule "Pick all sensor event messages"
when
$event: SensorEventMessage()
then
- Drools.getListener("EventSink_B").update($event);
+ SAM.getListener("EventSink_B").update($event);
end
Modified: sam/trunk/sam-trunk.iml
===================================================================
--- sam/trunk/sam-trunk.iml 2008-08-13 08:56:17 UTC (rev 238)
+++ sam/trunk/sam-trunk.iml 2008-08-13 09:39:31 UTC (rev 239)
@@ -154,18 +154,18 @@
</library>
</orderEntry>
<orderEntry type="module-library">
- <library name="M2 Dep: javax.xml:jaxb-impl:jar:2.1:compile">
+ <library name="M2 Dep: javax.xml.stream:stax-api:jar:1.0-2:compile">
<CLASSES>
- <root url="jar://$MODULE_DIR$/../../../../.m2/repository/javax/xml/jaxb-impl/2.1/jaxb-impl-2.1.jar!/" />
+ <root url="jar://$MODULE_DIR$/../../../../.m2/repository/javax/xml/stream/stax-api/1.0-2/stax-api-1.0-2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
- <library name="M2 Dep: javax.xml.stream:stax-api:jar:1.0-2:compile">
+ <library name="M2 Dep: com.sun.xml.bind:jaxb-impl:jar:2.1.6:compile">
<CLASSES>
- <root url="jar://$MODULE_DIR$/../../../../.m2/repository/javax/xml/stream/stax-api/1.0-2/stax-api-1.0-2.jar!/" />
+ <root url="jar://$MODULE_DIR$/../../../../.m2/repository/com/sun/xml/bind/jaxb-impl/2.1.6/jaxb-impl-2.1.6.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
15 years, 9 months
Overlord SVN: r238 - sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools.
by overlord-commits@lists.jboss.org
Author: heiko.braun(a)jboss.com
Date: 2008-08-13 04:56:17 -0400 (Wed, 13 Aug 2008)
New Revision: 238
Modified:
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/StreamOutputAdapter.java
Log:
Add support for collection types in output adapter
Modified: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/StreamOutputAdapter.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/StreamOutputAdapter.java 2008-08-13 07:51:15 UTC (rev 237)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/drools/StreamOutputAdapter.java 2008-08-13 08:56:17 UTC (rev 238)
@@ -24,6 +24,8 @@
import org.jboss.sam.StreamOutput;
import org.jboss.sam.EventMessage;
+import java.util.Collection;
+
/**
* @author Heiko.Braun <heiko.braun(a)jboss.com>
*/
@@ -49,8 +51,24 @@
private EventMessage[] adoptPayload(Object data)
{
- // TODO: deal with collection types
- return new EventMessage[] { new ObjectMessageAdaptor(data) };
+ EventMessage[] events = null;
+
+ if(data instanceof Collection)
+ {
+ Collection c = (Collection)data;
+ Object[] cAr = c.toArray();
+ events = new EventMessage[c.size()];
+ for(int i=0; i<c.size(); i++)
+ {
+ events[i] = new ObjectMessageAdaptor(cAr[i]);
+ }
+ }
+ else
+ {
+ events = new EventMessage[] { new ObjectMessageAdaptor(data) };
+ }
+
+ return events;
}
}
15 years, 9 months
Overlord SVN: r237 - cdl/trunk/samples.
by overlord-commits@lists.jboss.org
Author: jeff.yuchang
Date: 2008-08-13 03:51:15 -0400 (Wed, 13 Aug 2008)
New Revision: 237
Modified:
cdl/trunk/samples/pom.xml
Log:
* Add other two modules.
Modified: cdl/trunk/samples/pom.xml
===================================================================
--- cdl/trunk/samples/pom.xml 2008-08-13 07:17:08 UTC (rev 236)
+++ cdl/trunk/samples/pom.xml 2008-08-13 07:51:15 UTC (rev 237)
@@ -23,6 +23,8 @@
<modules>
<module>jbossesb/purchasing</module>
<module>jbossesb/creditAgency</module>
+ <module>jbossesb/supplier</module>
+ <module>jbossesb/broker</module>
</modules>
<build>
15 years, 9 months
Overlord SVN: r236 - in cdl/trunk/samples/jbossesb: broker/src/main/java/org/jboss/soa/overlord/samples/jbossesb/loan/broker and 1 other directory.
by overlord-commits@lists.jboss.org
Author: jeff.yuchang
Date: 2008-08-13 03:17:08 -0400 (Wed, 13 Aug 2008)
New Revision: 236
Modified:
cdl/trunk/samples/jbossesb/README.txt
cdl/trunk/samples/jbossesb/broker/src/main/java/org/jboss/soa/overlord/samples/jbossesb/loan/broker/SetCreditCheckRequestMessageAction.java
Log:
* Update document.
Modified: cdl/trunk/samples/jbossesb/README.txt
===================================================================
--- cdl/trunk/samples/jbossesb/README.txt 2008-08-13 03:27:18 UTC (rev 235)
+++ cdl/trunk/samples/jbossesb/README.txt 2008-08-13 07:17:08 UTC (rev 236)
@@ -8,13 +8,13 @@
- JBoss AS 4.2.2.GA or higher with the JBoss ESB SAR deployment (jbossesb.sar).
- JBossESB 4.3.GA
-Folder directories:
+Folders structure:
-------------------
-- client
-- broker
-- purchasing
-- creditAgency
-- supplier
+- client: It is for running examples' client.
+- broker: Broker participant. (Broker Example)
+- purchasing: Purchasing participant. (Purchase Example)
+- creditAgency: CredityAgency participant. (For both Broker and Purchase Example)
+- supplier: supplier participant. (For Broker example)
Settings required to edit before running:
========================================
@@ -25,7 +25,6 @@
- Before jbossesb-rosetta.jar and jbossesb-config-model.jar get published in jboss maven repository, you need to install these two artifacts into
your local repository by using following commands:
-
mvn install:install-file -Dfile=<path-to-rosetta> -DgroupId=org.jboss.jbossesb
-DartifactId=rosetta -Dversion=4.3 -Dpackaging=jar
mvn install:install-file -Dfile=<path-to-configmodel> -DgroupId=org.jboss.jbossesb
@@ -34,20 +33,22 @@
Notice: Here we are using jbossesb-rosetta 4.3 version, jbossesb-config-model 1.0.1 version.
-Instructions for purchasing example:
-===========================================
-To run the purchasing, follow these steps:
+Instructions for deploying the cdl-jbossesb.esb to the JBoss ESB server.
+==========================================
+1. At the $cdl/trunk: run: mvn install.
+2. Copy the 'cdl-jbossesb.esb' from the 'assembly/jbossesb/target' to JBoss ESB server deploy folder.
-1 - run your JBoss AS - you will need to have the 4.2.2 or higher (with JBossESB installed)
-2 - from the $JBossAS, execute the command to start the ESB: "bin/run.sh", or "bin/run.bat" for windows.
+Instructions for deploying samples:
+==========================================
+1. Please make sure you are setting the 'deploy.dir' in $samples/pom.xml properly.
+2. At the $cdl/trunk/samples, run: mvn install, it will deploy the 'purchasing.esb', 'broker.esb', 'creditAgency.esb', 'supplier.esb' to the server deploy folder.
+3. From the $JBossAS, execute the command to start the ESB server: "bin/run.sh", or "bin/run.bat" for windows.
-3 - from the $purchasing: execute the command to start the Hsql database: "ant startdb".
+Instructions for running purchasing example:
+===========================================
-4 - Open up another shell, from the $Purchasing, execute the command to deploy the "Purchasing": "mvn install"
- * this should deploy the ESB archive to your JBoss AS server/default.
-
-5 - from the $client, execute the command to run the client: "ant runClient"
+1 - from the $samples/jbossesb/client, execute the command to run the client: "ant runClient"
You will see following in the console.
[java] =========================================
@@ -56,25 +57,10 @@
[java] =========================================
-6 - you can be from the $purchasing to run "ant dbmanager" to open up the database browser to check the data.
-
-
-Instructions for broker example:
+Instructions for running broker example:
=======================================
-To run the broker, follow these steps:
-Currently, if you want to run the 'broker' example, please open up the 'jbossesb-properties.xml' in the $JBossAS/server/default/deploy/jbossesb.sar, update the 'org.jboss.soa.esb.jms.connectionPool' property value to '30', instead of '20'. It won't be needed to update this if we separate the Supplier & Credit Agency as another two esb artifacts.
-
-1 - run your JBoss AS - you will need to have the 4.2.2 or higher (with JBossESB installed)
-
-2 - from the $JBossAS, execute the command to start the ESB: "bin/run.sh", or "bin/run.bat" for windows.
-
-3 - from the $broker: execute the command to start the Hsql database: "ant startdb".
-
-4 - Open up another shell, from the $broker, execute the command to deploy the "broker": "mvn install"
- * this should deploy the ESB archive to your JBoss AS server/default.
-
-5 - from the $client, execute the command to run the client: "ant runBrokerClient"
+1 - from the $samples/jbossesb/client, execute the command to run the client: "ant runBrokerClient"
You will see following in the console.
[java] =========================================
[java] Request: <enquiry id="20" ></enquiry>
@@ -84,6 +70,30 @@
[java] Reply: <bookingReference id="20" supplierDesc = "{http://www.jboss.org/overlord/loanBroker}Supplier1">The quote of 10 has been confirmed.</bookingReference>
[java] =========================================
+Example scenario description:
+===============================
+1 - Purchasing example:
+------------
+The flow for this example would be:
-6 - you can be from the $broker to run "ant dbmanager" to open up the database browser to check the data.
+ * Users send an 'buy' request to broker
+ * Broker send a 'credit check' request to the credit agency.
+ * If the credit agency returns a successful message, then the Broker will send a 'BuyResponse' to user.
+ * If the credit agency returns a failed message, then the Broker will send a 'BuyFail' to user.
+
+2 - Broker example:
+----------
+
+The flow for this example would be:
+
+ * Users send an 'enquiry' request to broker
+ * Broker sends the request to one or more suppliers concurrently
+ * When all of the quote responses have been received, or a timeout expires, the available information is returned to the user.
+ * User decides whether to:
+ o Cancel the transaction, or
+ o Send a 'buy' request to the broker
+ * If a 'buy' request is received by the broker, it will send a 'credit check' request to the credit agency
+ * If the credit agency returns a successful message, then the Broker sends a 'buy' request to the supplier selected by the User (in the 'buy' request), followed by a confirmation back to the User
+ * If the credit agency returns a failed message, then the Broker will inform the User
+
Modified: cdl/trunk/samples/jbossesb/broker/src/main/java/org/jboss/soa/overlord/samples/jbossesb/loan/broker/SetCreditCheckRequestMessageAction.java
===================================================================
--- cdl/trunk/samples/jbossesb/broker/src/main/java/org/jboss/soa/overlord/samples/jbossesb/loan/broker/SetCreditCheckRequestMessageAction.java 2008-08-13 03:27:18 UTC (rev 235)
+++ cdl/trunk/samples/jbossesb/broker/src/main/java/org/jboss/soa/overlord/samples/jbossesb/loan/broker/SetCreditCheckRequestMessageAction.java 2008-08-13 07:17:08 UTC (rev 236)
@@ -40,7 +40,7 @@
Node node = XMLUtils.getNode((String)message.getBody().get());
String idValue = node.getAttributes().getNamedItem("id").getNodeValue();
- message.getBody().add("<CreditInformation id=\"" + idValue +"\"></CreditInformation>");
+ message.getBody().add("<creditInformation id=\"" + idValue +"\"></creditInformation>");
logger.info("Updated credit check request message: "+message.getBody().get());
15 years, 9 months