[overlord-commits] Overlord SVN: r241 - in sam/trunk/modules: core/src/main/java/org/jboss/sam/config and 6 other directories.
overlord-commits at lists.jboss.org
overlord-commits at lists.jboss.org
Wed Aug 13 08:54:02 EDT 2008
Author: heiko.braun at 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 at 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 at 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 at 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 at 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 at jboss.com>
+ */
+ at 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 at jboss.com>
*/
+ at 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 at 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 at 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 at 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 at 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 at 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);
More information about the overlord-commits
mailing list