geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From de...@apache.org
Subject svn commit: r988015 - /geronimo/sandbox/delos/status.patch
Date Mon, 23 Aug 2010 07:41:02 GMT
Author: delos
Date: Mon Aug 23 07:41:02 2010
New Revision: 988015

URL: http://svn.apache.org/viewvc?rev=988015&view=rev
Log:
upload a patch for review

Added:
    geronimo/sandbox/delos/status.patch

Added: geronimo/sandbox/delos/status.patch
URL: http://svn.apache.org/viewvc/geronimo/sandbox/delos/status.patch?rev=988015&view=auto
==============================================================================
--- geronimo/sandbox/delos/status.patch (added)
+++ geronimo/sandbox/delos/status.patch Mon Aug 23 07:41:02 2010
@@ -0,0 +1,142 @@
+Index: src/main/java/org/apache/geronimo/main/FrameworkLauncher.java
+===================================================================
+--- src/main/java/org/apache/geronimo/main/FrameworkLauncher.java	(revision 981165)
++++ src/main/java/org/apache/geronimo/main/FrameworkLauncher.java	(working copy)
+@@ -140,6 +140,9 @@
+         Runtime.getRuntime().addShutdownHook(new Thread() {
+             public void run() {
+                 FrameworkLauncher.this.destroy(false);
++                
++              //installer specific: remove lock file before JVM shutdown
++               LockFileGenerator.removeLockFile();
+             }
+         });
+         
+Index: src/main/java/org/apache/geronimo/main/LockFileGenerator.java
+===================================================================
+--- src/main/java/org/apache/geronimo/main/LockFileGenerator.java	(revision 0)
++++ src/main/java/org/apache/geronimo/main/LockFileGenerator.java	(revision 0)
+@@ -0,0 +1,88 @@
++
++
++package org.apache.geronimo.main;
++
++import java.io.File;
++import java.io.FileOutputStream;
++import java.io.IOException;
++import java.nio.channels.FileLock;
++
++
++/**
++ * This class is only used for generating lock file in java.io.tmpdir.
++ * Generated lock files will indicate if there is any server instance running.
++ * 
++ * 
++ * The class here will be used by Bootstapper.
++ * 
++ * Refer to ServerStartedRule.java in installer custom code com.ibm.wasce.installer.rules.ServerStartedRule

++ *
++ */
++class LockFileGenerator {
++	private static String lockFileSuffix = ".lock";
++	private static String lockFilePrefix = "GERONIMO";
++	private static String lockFileDirectory = ".tmp";
++    
++	private static File lockFile;
++	private static FileLock lock;
++	
++	public static File getLockFile(){
++		return lockFile;
++	}
++	
++	public static void generateLockFile() {
++		//each server instance only generate one lock file
++		if (lockFile !=null) return;
++		
++    	//get current server instance name    	
++		String filename = lockFilePrefix;		
++		String instanceName = System.getProperty(Utils.SERVER_NAME_SYS_PROP);
++		
++		//temp file prefix must be at least three chars, so we use lockFilePrefix as prefix
++		if (instanceName != null) filename = filename + instanceName;
++		
++		// get temp dir for lock files
++		File wasceTempDir = getTempDirForLockFile();
++		
++		//create temp file for the instance		
++		try {
++			//generate temp file because the file name is unique 
++			lockFile = File.createTempFile(filename, lockFileSuffix,wasceTempDir);
++			//temp file will be deleted if server exit normally
++			lockFile.deleteOnExit();
++			FileOutputStream os = new FileOutputStream(lockFile);
++			lock = os.getChannel().lock();			
++		} catch (IOException e) {
++			//ignore: fail to lock the temp file shouldn't stop the starting of server
++		}
++	}
++	
++	private static File getTempDirForLockFile(){
++		//get temp directory for lock files
++		String tempDir;
++		try {
++			tempDir = Utils.getGeronimoHome().getAbsolutePath()+"/"+lockFileDirectory;
++		} catch (IOException e) {
++			//ignore: fail to lock the temp file shouldn't stop the starting of server
++			return null;
++		}
++		
++		File wasceTempDir = new File(tempDir);
++		if (!wasceTempDir.exists()) wasceTempDir.mkdir();
++		
++		return wasceTempDir;
++	}
++	
++	public static void removeLockFile(){
++		//we force to remove lock file 
++		//because temp file won't be removed when server exit abnormally
++		if (lock!=null)
++			try {
++				lock.release();
++			} catch (IOException e) {
++				//ignore
++			}
++		if (lockFile!=null&&lockFile.exists())
++			lockFile.delete();
++	}
++}
+Index: src/main/java/org/apache/geronimo/main/Bootstrapper.java
+===================================================================
+--- src/main/java/org/apache/geronimo/main/Bootstrapper.java	(revision 981165)
++++ src/main/java/org/apache/geronimo/main/Bootstrapper.java	(working copy)
+@@ -27,7 +27,8 @@
+  * @version $Rev$ $Date$
+  */
+ public class Bootstrapper extends FrameworkLauncher {
+-    
++	
++
+     private boolean waitForStop = true;    
+     private List<String> bundles;
+ 
+@@ -44,6 +45,9 @@
+         
+     public int execute(Object opaque) {
+         try {
++        	//installer specific: generate lock file to indicate if server is running
++        	LockFileGenerator.generateLockFile();
++        	
+             launch();
+         } catch (Throwable e) {
+             System.err.println("Error launching framework: " + e);
+@@ -78,7 +82,9 @@
+         }
+     }
+ 
+-    public Main getMain() {
++    
++
++	public Main getMain() {
+         ServiceTracker tracker = new ServiceTracker(getFramework().getBundleContext(), Main.class.getName(),
null);
+         tracker.open();        
+         Main geronimoMain = null;



Mime
View raw message