[jboss-svn-commits] JBL Code SVN: r12751 - labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jun 21 14:05:35 EDT 2007
Author: mark.proctor at jboss.com
Date: 2007-06-21 14:05:35 -0400 (Thu, 21 Jun 2007)
New Revision: 12751
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/DirectoryScanner.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileScanner.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/PackageProvider.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleBaseAgent.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleBaseAgentCache.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/URLScanner.java
Log:
-formatted
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/DirectoryScanner.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/DirectoryScanner.java 2007-06-21 18:02:29 UTC (rev 12750)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/DirectoryScanner.java 2007-06-21 18:05:35 UTC (rev 12751)
@@ -13,32 +13,34 @@
*/
public class DirectoryScanner extends PackageProvider {
- private File[] currentList;
+ private File[] currentList;
private FileScanner scanner;
- private File dir;
+ private File dir;
- void configure(Properties config) {
+ void configure(Properties config) {
String d = config.getProperty( RuleBaseAgent.DIRECTORY );
-
+
//now check to see whats in them dir...
- dir = new File(d);
- if (!(dir.isDirectory() && dir.exists())) {
- throw new IllegalArgumentException("The directory " + d + "is not valid.");
+ dir = new File( d );
+ if ( !(dir.isDirectory() && dir.exists()) ) {
+ throw new IllegalArgumentException( "The directory " + d + "is not valid." );
}
-
+
this.currentList = dir.listFiles();
scanner = new FileScanner();
scanner.setFiles( currentList );
-
+
}
- void updateRuleBase(RuleBase rb, boolean removeExistingPackages) {
- if (currentList.length != dir.listFiles().length) {
+ void updateRuleBase(RuleBase rb,
+ boolean removeExistingPackages) {
+ if ( currentList.length != dir.listFiles().length ) {
currentList = dir.listFiles();
scanner = new FileScanner();
scanner.setFiles( currentList );
}
- scanner.updateRuleBase( rb, removeExistingPackages );
+ scanner.updateRuleBase( rb,
+ removeExistingPackages );
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileScanner.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileScanner.java 2007-06-21 18:02:29 UTC (rev 12750)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileScanner.java 2007-06-21 18:05:35 UTC (rev 12751)
@@ -34,7 +34,7 @@
* This sets the list of files to be monitored.
* This takes a list of paths and files (not directories).
*/
- void configure(Properties config) {
+ void configure(Properties config) {
List paths = RuleBaseAgent.list( config.getProperty( RuleBaseAgent.FILES ) );
files = new File[paths.size()];
for ( int i = 0; i < paths.size(); i++ ) {
@@ -45,7 +45,7 @@
files[i] = file;
}
}
-
+
/**
* An alternative way to configure.
*/
@@ -58,13 +58,15 @@
* If there was an error reading the packages, this will not fail, it will
* just do nothing (as there may be a temporary IO issue).
*/
- void updateRuleBase(RuleBase rb, boolean removeExistingPackages) {
+ void updateRuleBase(RuleBase rb,
+ boolean removeExistingPackages) {
Package[] changes = getChangeSet();
- if (changes == null) return;
+ if ( changes == null ) return;
for ( int i = 0; i < changes.length; i++ ) {
Package p = changes[i];
if ( removeExistingPackages ) {
- removePackage( p.getName(), rb );
+ removePackage( p.getName(),
+ rb );
}
try {
rb.addPackage( p );
@@ -78,7 +80,8 @@
* Remove the package from the rulebase if it exists in it.
* If it does not, does nothing.
*/
- private void removePackage(String name, RuleBase rb) {
+ private void removePackage(String name,
+ RuleBase rb) {
Package[] ps = rb.getPackages();
if ( ps == null ) return;
for ( int i = 0; i < ps.length; i++ ) {
@@ -102,9 +105,11 @@
List list = new ArrayList();
for ( int i = 0; i < files.length; i++ ) {
File f = files[i];
- if ( hasChanged( f.getPath(), this.lastUpdated, f.lastModified() ) ) {
+ if ( hasChanged( f.getPath(),
+ this.lastUpdated,
+ f.lastModified() ) ) {
Package p = readPackage( f );
- if (p == null) return null;
+ if ( p == null ) return null;
list.add( p );
}
}
@@ -115,16 +120,15 @@
* If an exception occurs, it is noted, but ignored.
* Especially IO, as generally they are temporary.
*/
- private static Package readPackage(File pkgFile) {
-
+ private static Package readPackage(File pkgFile) {
+
Package p1_ = null;
ObjectInputStream in;
try {
in = new DroolsObjectInputStream( new FileInputStream( pkgFile ) );
p1_ = (Package) in.readObject();
in.close();
-
-
+
} catch ( FileNotFoundException e ) {
//throw new RuntimeDroolsException("Unable to open file: [" + pkgFile.getPath() + "]", e);
} catch ( IOException e ) {
@@ -135,15 +139,19 @@
return p1_;
}
- boolean hasChanged(String path, Map updates, long fileLastModified) {
+ boolean hasChanged(String path,
+ Map updates,
+ long fileLastModified) {
if ( !updates.containsKey( path ) ) {
- updates.put( path, new Long( fileLastModified ) );
+ updates.put( path,
+ new Long( fileLastModified ) );
return true;
} else {
Long last = (Long) updates.get( path );
if ( last.intValue() < fileLastModified ) {
- updates.put( path, new Long( fileLastModified ) );
+ updates.put( path,
+ new Long( fileLastModified ) );
return true;
} else {
return false;
@@ -151,16 +159,14 @@
}
}
-
+
public String toString() {
StringBuffer buf = new StringBuffer();
for ( int i = 0; i < files.length; i++ ) {
- File f= files[i];
+ File f = files[i];
buf.append( f.getPath() + " " );
}
return buf.toString();
}
-
-
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/PackageProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/PackageProvider.java 2007-06-21 18:02:29 UTC (rev 12750)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/PackageProvider.java 2007-06-21 18:05:35 UTC (rev 12751)
@@ -16,15 +16,12 @@
* If there was an error reading the packages, this will not fail, it will
* just do nothing (as there may be a temporary IO issue).
*/
- abstract void updateRuleBase(RuleBase rb, boolean removeExistingPackages);
-
-
+ abstract void updateRuleBase(RuleBase rb,
+ boolean removeExistingPackages);
+
/**
* This will be passed the entire config.
*/
abstract void configure(Properties config);
-
-
-
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleBaseAgent.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleBaseAgent.java 2007-06-21 18:02:29 UTC (rev 12750)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleBaseAgent.java 2007-06-21 18:05:35 UTC (rev 12751)
@@ -49,24 +49,26 @@
*/
public static final String NEW_INSTANCE = "newInstance";
public static final String FILES = "file";
- public static final String DIRECTORY = "dir";
+ public static final String DIRECTORY = "dir";
//public static final String URIS = "uri";
public static final String POLL_INTERVAL = "poll";
/**
* Here is where we have a map of providers to the key that appears on the configuration.
*/
- public static Map PACKAGE_PROVIDERS = new HashMap() {
+ private static Map PACKAGE_PROVIDERS = new HashMap() {
{
- put( FILES, FileScanner.class );
- put( DIRECTORY, DirectoryScanner.class);
+ put( FILES,
+ FileScanner.class );
+ put( DIRECTORY,
+ DirectoryScanner.class );
}
};
/**
* This is true if the rulebase is created anew each time.
*/
- boolean newInstance;
+ private boolean newInstance;
/**
* The rule base that is being managed.
@@ -77,7 +79,7 @@
* The timer that is used to monitor for changes and deal with them.
*/
private Timer timer;
-
+
/**
* The providers that actually do the work.
*/
@@ -87,34 +89,38 @@
* Properties configured to load up packages into a rulebase (and monitor them
* for changes).
*/
- public RuleBaseAgent(
- Properties config) {
+ public RuleBaseAgent(Properties config) {
init( config );
}
private void init(Properties config) {
-
- boolean newInstance = Boolean.valueOf( config.getProperty( NEW_INSTANCE, "false" ) ).booleanValue();
- int secondsToRefresh = Integer.parseInt( config.getProperty( POLL_INTERVAL, "-1" ) );
+ boolean newInstance = Boolean.valueOf( config.getProperty( NEW_INSTANCE,
+ "false" ) ).booleanValue();
+ int secondsToRefresh = Integer.parseInt( config.getProperty( POLL_INTERVAL,
+ "-1" ) );
+
providers = new ArrayList();
for ( Iterator iter = config.keySet().iterator(); iter.hasNext(); ) {
String key = (String) iter.next();
- PackageProvider prov = getProvider( key, config );
- if (prov != null) {
- providers.add( prov ) ;
+ PackageProvider prov = getProvider( key,
+ config );
+ if ( prov != null ) {
+ providers.add( prov );
}
}
- configure( newInstance, providers, secondsToRefresh );
+ configure( newInstance,
+ providers,
+ secondsToRefresh );
}
-
+
/**
* Pass in the name and full path to a config file that is on the classpath.
*/
public RuleBaseAgent(String propsFileName) {
- init(loadFromProperties( propsFileName ));
+ init( loadFromProperties( propsFileName ) );
}
Properties loadFromProperties(String propsFileName) {
@@ -123,18 +129,20 @@
try {
props.load( in );
return props;
-
+
} catch ( IOException e ) {
- throw new RuntimeDroolsException("Unable to load properties. Needs to be the path and name of a config file on your classpath.",e);
+ throw new RuntimeDroolsException( "Unable to load properties. Needs to be the path and name of a config file on your classpath.",
+ e );
}
}
/**
* Return a configured provider ready to go.
*/
- private PackageProvider getProvider(String key, Properties config) {
- if (!PACKAGE_PROVIDERS.containsKey( key )) {
- return null;
+ private PackageProvider getProvider(String key,
+ Properties config) {
+ if ( !PACKAGE_PROVIDERS.containsKey( key ) ) {
+ return null;
}
Class clz = (Class) PACKAGE_PROVIDERS.get( key );
try {
@@ -150,22 +158,26 @@
}
}
- synchronized void configure(boolean newInstance, final List providers, int secondsToRefresh) {
+ synchronized void configure(boolean newInstance,
+ final List providers,
+ int secondsToRefresh) {
this.newInstance = newInstance;
//run it the first time for each.
- refreshRuleBase( );
+ refreshRuleBase();
if ( secondsToRefresh != -1 ) {
int interval = secondsToRefresh * 1000;
//now schedule it for polling
timer = new Timer( true );
timer.schedule( new TimerTask() {
- public void run() {
- refreshRuleBase();
+ public void run() {
+ refreshRuleBase();
- }
- }, interval, interval );
+ }
+ },
+ interval,
+ interval );
}
}
@@ -182,7 +194,8 @@
if ( this.newInstance || this.ruleBase == null ) {
ruleBase = RuleBaseFactory.newRuleBase();
}
- prov.updateRuleBase( this.ruleBase, !this.newInstance );
+ prov.updateRuleBase( this.ruleBase,
+ !this.newInstance );
}
/**
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleBaseAgentCache.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleBaseAgentCache.java 2007-06-21 18:02:29 UTC (rev 12750)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleBaseAgentCache.java 2007-06-21 18:05:35 UTC (rev 12751)
@@ -6,16 +6,15 @@
public class RuleBaseAgentCache {
-
private static final RuleBaseAgentCache INSTANCE = new RuleBaseAgentCache();
-
+
private RuleBaseAgentCache() {
}
-
+
public static RuleBaseAgentCache instance() {
return INSTANCE;
}
-
+
/**
* Return a rulebase by name.
* This name may be the name of a pre configured rulebase,
@@ -23,19 +22,17 @@
* on the classpath.
*/
public RuleBase getRuleBase(String name) {
- throw new UnsupportedOperationException("Not done yet !");
+ throw new UnsupportedOperationException( "Not done yet !" );
}
-
/**
* Pass in a pre populated properties file.
* It will then map this config to the given name for future use.
* @return A RuleBase ready to go.
*/
- public RuleBase configureRuleBase(String name, Properties props) {
+ public RuleBase configureRuleBase(String name,
+ Properties props) {
return null;
}
-
-
-
+
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/URLScanner.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/URLScanner.java 2007-06-21 18:02:29 UTC (rev 12750)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/URLScanner.java 2007-06-21 18:05:35 UTC (rev 12751)
@@ -14,61 +14,54 @@
public class URLScanner {
-
-
-
public URLScanner(String uri) throws Exception {
try {
-
+
checkLastUpdated( uri );
- URL url = new URL(uri);
-
+ URL url = new URL( uri );
+
URLConnection con = url.openConnection();
HttpURLConnection httpCon = (HttpURLConnection) con;
httpCon.setRequestMethod( "GET" );
InputStream in = httpCon.getInputStream();
-
- DroolsObjectInputStream oin = new DroolsObjectInputStream(in);
+
+ DroolsObjectInputStream oin = new DroolsObjectInputStream( in );
Package p = (Package) oin.readObject();
in.close();
-
-
- System.err.println(p.getName());
-
+
+ System.err.println( p.getName() );
+
} catch ( IOException e ) {
- throw new RuntimeDroolsException(e);
+ throw new RuntimeDroolsException( e );
}
-
+
}
private void checkLastUpdated(String uri) throws MalformedURLException,
IOException,
ProtocolException {
- URL url = new URL(uri);
-
+ URL url = new URL( uri );
+
URLConnection con = url.openConnection();
HttpURLConnection httpCon = (HttpURLConnection) con;
httpCon.setRequestMethod( "HEAD" );
-
-
-
+
//if this is null, then its not cool
- System.err.println(httpCon.getHeaderField( "lastModified" ));
-
+ System.err.println( httpCon.getHeaderField( "lastModified" ) );
+
//can check for '200 OK' to make sure its kosher.
- System.err.println(httpCon.getHeaderFields());
-
+ System.err.println( httpCon.getHeaderFields() );
+
String status = httpCon.getHeaderField( null );
-
-
- System.err.println(status);
-
+
+ System.err.println( status );
+
httpCon.disconnect();
}
-
+
public static void main(String[] args) throws Exception {
- URLScanner scan = new URLScanner("http://localhost:8888/org.drools.brms.JBRMS/package/com.billasurf.manufacturing.plant/SNAP");
-
+ URLScanner scan = new URLScanner( "http://localhost:8888/org.drools.brms.JBRMS/package/com.billasurf.manufacturing.plant/SNAP" );
+
}
-
+
}
More information about the jboss-svn-commits
mailing list