You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by th...@apache.org on 2012/04/12 13:53:22 UTC

svn commit: r1325210 - in /river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart: ./ config/

Author: thobbs
Date: Thu Apr 12 11:53:22 2012
New Revision: 1325210

URL: http://svn.apache.org/viewvc?rev=1325210&view=rev
Log:
Starting to get easy config working with reggie

Added:
    river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/
    river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/ConventionalLookupServiceConfiguration.java
    river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/Options.java
    river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/Setting.java
    river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/start-reggie.config
Modified:
    river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/CheckServices.java
    river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/StartLookupService.java

Modified: river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/CheckServices.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/CheckServices.java?rev=1325210&r1=1325209&r2=1325210&view=diff
==============================================================================
--- river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/CheckServices.java (original)
+++ river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/CheckServices.java Thu Apr 12 11:53:22 2012
@@ -47,10 +47,10 @@ public class CheckServices {
 		
 		checkHttpServer(port);
 		checkLookupServices();
-		checkSpaces();
-		checkTransactionManagers();
-		
-		checkAll();
+//		checkSpaces();
+//		checkTransactionManagers();
+//		
+//		checkAll();
 	}
 
 	private static void checkHttpServer(int port) throws IOException {

Modified: river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/StartLookupService.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/StartLookupService.java?rev=1325210&r1=1325209&r2=1325210&view=diff
==============================================================================
--- river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/StartLookupService.java (original)
+++ river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/StartLookupService.java Thu Apr 12 11:53:22 2012
@@ -19,10 +19,15 @@
 package org.apache.river.extra.easystart;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.logging.Logger;
 
+import org.apache.river.extra.easystart.config.ConventionalLookupServiceConfiguration;
+
+import net.jini.config.Configuration;
 import net.jini.config.ConfigurationException;
 
+
 import com.sun.jini.start.ServiceStarter;
 
 public class StartLookupService {
@@ -36,8 +41,9 @@ public class StartLookupService {
 	/**
 	 * @param args
 	 * @throws ConfigurationException 
+	 * @throws IOException 
 	 */
-	public static void main(String[] args) throws ConfigurationException {
+	public static void main(String[] args) throws ConfigurationException, IOException {
 		validateArgs(args);
 		
 		final String RIVER_HOME = args[RIVER_HOME_INDEX];
@@ -49,22 +55,39 @@ public class StartLookupService {
 		final String riverHome = "/home/tom/projects/river/easystart";
 		final String pathToConfig = "/home/tom/projects/river/easystart/src-extra/empty.config";
 		final String pathToPolicy = "/home/tom/projects/river/easystart/src-extra/outrigger.policy";
-		final String classpath = "/home/tom/projects/river/easystart/lib/outrigger.jar";
 		
-		LookupServiceConfiguration config = new LookupServiceConfiguration(8080,
-				riverHome,
-				new AbsolutePath(pathToConfig),
-				new AbsolutePath(pathToPolicy),
-				new AbsolutePath[] {
-					new AbsolutePath(classpath)
-				}
-		);
-		config.addLookupGroup("LUG1");
-		config.addLookupGroup("LUG2");
-		config.addMemberGroup("Lester");
-		config.addMemberGroup("Jeff");
+		//this works because these files are in river-extras.jar which is on the CP
+//		final String pathToConfig = "empty.config";
+//		final String pathToPolicy = "outrigger.policy";
+		
+		final String classpath = "/home/tom/projects/river/easystart/lib/reggie.jar";
+		
+//		LookupServiceConfiguration config = new LookupServiceConfiguration(8080,
+//				riverHome,
+//				new AbsolutePath(pathToConfig),
+//				new AbsolutePath(pathToPolicy),
+//				new AbsolutePath[] {
+//					new AbsolutePath(classpath)
+////					new AbsolutePath("/home/tom/projects/river/easystart/lib/river-extras.jar")
+//				}
+//		);
+//		config.addLookupGroup("LUG1");
+//		config.addLookupGroup("LUG2");
+//		config.addMemberGroup("Lester");
+//		config.addMemberGroup("Jeff");
+//		config.addRequiredJar("reggie-dl.jar");
+//		config.addRequiredJar("jsk-dl.jar");
+////		config.addRequiredJar("river-extras.jar");
+		
+//		LookupServiceConfiguration config = new LookupServiceConfiguration();
+//		VelocityConfigurationBuilder vcb = new VelocityConfigurationBuilder();
+//		vcb.setCodebase("http://localhost:8080/reggie-dl.jar http://localhost:8080/jsk-dl.jar");
+//		Configuration config = vcb.createConfiguration();
 		
+//		Configuration config = new ConventionalLookupServiceConfiguration(new String[0]);
+		Configuration config = ConventionalLookupServiceConfiguration.config();
 		ServiceStarter.main(config);
+		
 	}
 
 	private static void validateArgs(String[] args) {

Added: river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/ConventionalLookupServiceConfiguration.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/ConventionalLookupServiceConfiguration.java?rev=1325210&view=auto
==============================================================================
--- river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/ConventionalLookupServiceConfiguration.java (added)
+++ river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/ConventionalLookupServiceConfiguration.java Thu Apr 12 11:53:22 2012
@@ -0,0 +1,119 @@
+package org.apache.river.extra.easystart.config;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import net.jini.config.ConfigurationException;
+import net.jini.config.ConfigurationFile;
+
+import org.apache.river.config.builder.VelocityConfigurationBuilder;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+
+public class ConventionalLookupServiceConfiguration extends ConfigurationFile {
+
+	private static final Logger LOGGER = Logger.getLogger(ConventionalLookupServiceConfiguration.class.getName());
+	
+//	private static final Reader fileReader() {
+//		InputStream in = Options.class.getResourceAsStream("start-reggie.config");
+//		return new BufferedReader(new InputStreamReader(in));
+//	}
+	
+	public static ConventionalLookupServiceConfiguration config() throws IOException, ConfigurationException {
+		
+		Options opts = new Options();
+		opts.PACKAGE_NAME.setOverride("com.sun.jini.reggie");
+//		opts.RIVER_HOME;  - no override for this
+		opts.HTTP_PORT.setOverride("8080");
+		opts.JINI_PORT.setOverride("4160");
+//		opts.setGroup("lappy");
+//		opts.setHttpPort("8080");
+//		opts.setJiniPort(4931);
+//		opts.setPackageName("com.sun.jini.reggie");
+		
+		Properties p = new Properties();
+		p.load( VelocityConfigurationBuilder.class.getResourceAsStream("velocity.properties") );
+		VelocityEngine ve = new VelocityEngine(p);
+		VelocityContext context = new VelocityContext();
+		
+		StringBuilder options = new StringBuilder();
+		StringBuilder defaults = new StringBuilder();
+		String key = opts.PACKAGE_NAME.getOverride()+'.';
+		for(Setting setting : opts.OPTIONS) {
+			String format = setting.getFormatter();
+			if(setting.isServiceDescription()) {
+	        	
+	        	String name = key + setting.getName();
+	        	
+	        	options
+	        		.append(",\"")
+	        		.append(name)
+	        		.append('=')
+	        		.append(String.format(format, setting.getOverride()))
+	        		.append("\"\n");
+	        	
+	        	defaults
+	        		.append(setting.getName())
+	        		.append('=')
+	        		.append(String.format(format, setting.getDefault()))
+	        		.append(";\n");
+			} else {
+	        	context.put(setting.getName(),
+				String.format(format, setting.getOverride()));
+			}
+		}
+		
+        context.put("defaults", defaults.toString());
+        context.put("options", options.toString());
+//        for(Setting setting : opts.OPTIONS) {
+//        	String format = setting.getFormatter();
+//        	context.put("default_"+setting.getName(),
+//        			    String.format(format, setting.getDefault()));
+//        	context.put(setting.getName(),
+//        				String.format(format, setting.getOverride()));
+//        }
+//        context.put("servicePackageName", String.format("\"%s\"",opts.getPackageName()+" {}"));
+//        context.put("riverHome", String.format("\"%s\"",opts.getRiverHome()) );
+//        context.put("groups", String.format("\\\"%s\\\"",opts.getGroup()) );
+//        context.put("httpPort", opts.getHttpPort());
+//        context.put("jiniPort", opts.getJiniPort());
+        
+        Template template = ve.getTemplate( Options.class.getResource("start-reggie.config").toExternalForm() );
+        
+        StringWriter sw = new StringWriter();
+
+        template.merge(context, sw);
+        
+        String s = sw.toString();
+        
+        LOGGER.warning(s);
+        
+        StringReader sr = new StringReader(s);
+        
+        return new ConventionalLookupServiceConfiguration(sr, new String[0]);//opts.getOptionsArray());
+	}
+	
+	private ConventionalLookupServiceConfiguration(Reader reader, String[] options) throws ConfigurationException {
+		super(reader,options);
+	}
+	
+//	public ConventionalLookupServiceConfiguration(String[] options) throws ConfigurationException {
+//		super(fileReader(), options);
+//	}
+
+	@Override
+	public Object getEntry(String component, String name, Class type,
+			Object defaultValue) throws ConfigurationException {
+		if("initialMemberGroups".equals(name)) {
+//			return new String[0];
+			return super.getEntry(component, name, type, defaultValue);
+		} else {
+			return super.getEntry(component, name, type, defaultValue);
+		}
+	}
+}

Added: river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/Options.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/Options.java?rev=1325210&view=auto
==============================================================================
--- river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/Options.java (added)
+++ river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/Options.java Thu Apr 12 11:53:22 2012
@@ -0,0 +1,82 @@
+package org.apache.river.extra.easystart.config;
+
+import java.util.logging.Logger;
+
+public class Options {
+
+	private static final Logger LOGGER = Logger.getLogger(Options.class.getName());
+
+	public static final String NO_FORMAT = "%s";
+	public static final String STRING_FORMAT = "\"%s\"";
+	public static final String INTEGER_FORMAT = "%s";
+	
+	private static final String RIVER_HOME_ENV_NAME = "RIVER_HOME";
+	private static String RIVER_HOME_DIR;
+	static {
+		RIVER_HOME_DIR = (String) System.getProperties().get(RIVER_HOME_ENV_NAME);
+		if(null == RIVER_HOME_DIR) {
+			LOGGER.severe(RIVER_HOME_ENV_NAME+" has not been set");
+			RIVER_HOME_DIR = ".";
+		} else {
+			LOGGER.severe("Using "+RIVER_HOME_ENV_NAME+"="+RIVER_HOME_DIR);
+		}
+	}
+	
+	public Setting RIVER_HOME = new Setting("riverHome", RIVER_HOME_DIR, STRING_FORMAT, false);
+	public Setting PACKAGE_NAME = new Setting("servicePackageName", "org.apache.river", NO_FORMAT, false);
+	
+	public Setting JINI_PORT = new Setting("initialUnicastDiscoveryPort", "4160", INTEGER_FORMAT, true);
+	public Setting HTTP_PORT = new Setting("httpPort", "8080", INTEGER_FORMAT, false);
+	
+	public Setting[] OPTIONS = new Setting[] {
+			RIVER_HOME,
+			PACKAGE_NAME,
+			JINI_PORT,
+			HTTP_PORT
+	};
+	
+//	private static final String RIVER_HOME = "RIVER_HOME";
+//	private static final String RIVER_HOME_DIR;
+//	static {
+//		RIVER_HOME_DIR = (String) System.getProperties().get(RIVER_HOME);
+//		if(null == RIVER_HOME_DIR) {
+//			LOGGER.severe(RIVER_HOME+" has not been set");
+//		} else {
+//			LOGGER.severe("Using "+RIVER_HOME+"="+RIVER_HOME_DIR);
+//		}
+//		
+//	}
+//	
+//	private String group = "grp";
+//	private String httpPort = "80";
+//	private int jiniPort = 4160;
+//	private String packageName = "";
+//	
+//	public String getRiverHome() {
+//		return RIVER_HOME_DIR;
+//	}
+//	
+//	public void setGroup(String g) { this.group = g; }
+//	public String getGroup() { return this.group; }
+//
+//	public void setHttpPort(String port) { this.httpPort = port; }
+//	public String getHttpPort() { return this.httpPort; }
+//	
+//	public void setJiniPort(int port) { this.jiniPort = port; }
+//	public int getJiniPort() { return this.jiniPort; }
+//
+//	public String[] getOptionsArray() {
+//		return new String[] {
+//				getRiverHome()+"src-extra/empty.config",
+//				"com.sun.jini.reggie.initialMemberGroups = new String[] {\""+ group+"\"}",
+//				"com.sun.jini.reggie.initialUnicastDiscoveryPort = "+jiniPort
+//		};
+//	}
+//
+//	public void setPackageName(String packageName) {
+//		this.packageName = packageName;
+//	}
+//	public String getPackageName() {
+//		return this.packageName;
+//	}
+}

Added: river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/Setting.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/Setting.java?rev=1325210&view=auto
==============================================================================
--- river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/Setting.java (added)
+++ river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/Setting.java Thu Apr 12 11:53:22 2012
@@ -0,0 +1,56 @@
+package org.apache.river.extra.easystart.config;
+
+
+/**
+ * This is an enum-like class which encapsulates some default options when
+ * using River services.
+ * 
+ * It is not an enum, on purpose, in order to allow other users to easily
+ * extend and replace as required.
+ * 
+ * @author Tom Hobbs
+ *
+ */
+public class Setting {
+
+//	public Setting<String[]> LOOKUP_GROUPS = new Setting<String[]>(LookupDiscovery.ALL_GROUPS);
+//	public Setting<String[]> MEMBER_GROUPS = new Setting<String[]>(LookupDiscovery.ALL_GROUPS);
+	
+	private final String name, defaultValue, format;
+	private final boolean serviceDescription;
+	private String override;
+	
+	protected Setting(String name, String defaultValue, String format, boolean serviceDescription) {
+		this.name = name;
+		this.defaultValue = defaultValue;
+		this.format = format;
+		this.serviceDescription = serviceDescription;
+		
+		this.override = defaultValue;
+	}
+	
+	public String getName() {
+		return this.name;
+	}
+	
+	public String getDefault() {
+		return defaultValue;
+	}
+	
+	public String getFormatter() {
+		return format;
+	}
+	
+	public boolean isServiceDescription() {
+		return serviceDescription;
+	}
+	
+	public void setOverride(String override) {
+		this.override = override;
+	}
+	
+	public String getOverride() {
+		return this.override;
+	}
+	
+}

Added: river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/start-reggie.config
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/start-reggie.config?rev=1325210&view=auto
==============================================================================
--- river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/start-reggie.config (added)
+++ river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/config/start-reggie.config Thu Apr 12 11:53:22 2012
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import net.jini.jrmp.JrmpExporter;
+
+import com.sun.jini.config.ConfigUtil;
+import com.sun.jini.start.NonActivatableServiceDescriptor;
+import com.sun.jini.start.ServiceDescriptor;
+
+com.sun.jini.start {
+
+    private static codebase =
+	ConfigUtil.concat(
+	    new Object[] { 
+		"http://", ConfigUtil.getHostName(), ":${httpPort}/reggie-dl.jar",
+		" ",
+        "http://", ConfigUtil.getHostName(), ":${httpPort}/jsk-dl.jar" } );
+        
+    private static policy = ${riverHome}+"/src-extra/policy.all";
+    private static classpath = ${riverHome}+"/lib/reggie.jar";
+
+    static serviceDescriptors = new ServiceDescriptor[] {
+	new NonActivatableServiceDescriptor(
+	    codebase, 
+	    policy, 
+	    classpath,
+	    "com.sun.jini.reggie.TransientRegistrarImpl",
+	    new String[] { 
+	    "-"
+	    //overrides
+	    ${options}
+	    //overrides end
+	    /*,
+	    "com.sun.jini.reggie.initialMemberGroups=new String[] {${groups}}"
+	    "com.sun.jini.reggie.initialUnicastDiscoveryPort=${initialUnicastDiscoveryPort}",
+	    "com.sun.jini.reggie.serverExporter="${serverExporter}"
+	    */
+	    }
+	    )
+    };
+}
+
+${servicePackageName} {
+
+//defaults
+    ${defaults}
+//defaults end
+
+    initialMemberGroups = new String[] {};
+//    initialUnicastDiscoveryPort = ${default_initialUnicastDiscoveryPort}; //4160;
+    serverExporter=new net.jini.jrmp.JrmpExporter();
+
+//    //static serverExporter = new BasicJeriExporter( ${registryEndpoint}, new BasicILFactory());
+//    serverExporter=new net.jini.jrmp.JrmpExporter();
+//
+}