- pass the svn revision as format version (for more detailed verification)
- add an 'autoreload' setting that makes Gridworks autoreload its self if a class gets changed (this is useful to make development cycles faster when working on the java code with autocompiling IDE like Eclipse or IDEA) git-svn-id: http://google-refine.googlecode.com/svn/trunk@372 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
d1e72e7797
commit
521acda025
@ -103,7 +103,7 @@
|
|||||||
workingdirectory="$APP_PACKAGE/Contents/Resources"
|
workingdirectory="$APP_PACKAGE/Contents/Resources"
|
||||||
jvmversion="1.6+"
|
jvmversion="1.6+"
|
||||||
bundleid="com.metaweb.gridworks.Gridworks"
|
bundleid="com.metaweb.gridworks.Gridworks"
|
||||||
vmoptions="${java.options}"
|
vmoptions="-Dgridworks.version=${revision} ${java.options}"
|
||||||
antialiasedgraphics="true"
|
antialiasedgraphics="true"
|
||||||
antialiasedtext="true"
|
antialiasedtext="true"
|
||||||
liveresize="true"
|
liveresize="true"
|
||||||
@ -138,7 +138,7 @@
|
|||||||
<cp>lib/*.jar</cp>
|
<cp>lib/*.jar</cp>
|
||||||
</classPath>
|
</classPath>
|
||||||
<jre minVersion="1.6.0" jdkPreference="preferJre" initialHeapSize="256" maxHeapSize="1024">
|
<jre minVersion="1.6.0" jdkPreference="preferJre" initialHeapSize="256" maxHeapSize="1024">
|
||||||
<opt>-Djava.library.path=lib/native/windows</opt>
|
<opt>-Djava.library.path=lib/native/windows -Dgridworks.version=${revision}</opt>
|
||||||
</jre>
|
</jre>
|
||||||
<versionInfo
|
<versionInfo
|
||||||
fileVersion="${num_version}.0.0"
|
fileVersion="${num_version}.0.0"
|
||||||
|
@ -41,6 +41,9 @@ where [options] include:
|
|||||||
-m <memory> max memory heap size to use
|
-m <memory> max memory heap size to use
|
||||||
default: 1024M
|
default: 1024M
|
||||||
|
|
||||||
|
-a autoreload if class files change
|
||||||
|
default: false
|
||||||
|
|
||||||
--debug enable JVM debugging (on port 8000)
|
--debug enable JVM debugging (on port 8000)
|
||||||
|
|
||||||
--jmx enable JMX monitoring (for jconsole and jvisualvm)
|
--jmx enable JMX monitoring (for jconsole and jvisualvm)
|
||||||
@ -271,6 +274,10 @@ run() {
|
|||||||
OPTS="-Dgridworks.data_dir=$GRIDWORKS_DATA_DIR $OPTS"
|
OPTS="-Dgridworks.data_dir=$GRIDWORKS_DATA_DIR $OPTS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
get_revision
|
||||||
|
|
||||||
|
OPTS="-Dgridworks.version=$REVISION $OPTS"
|
||||||
|
|
||||||
CLASSPATH="$GRIDWORKS_BUILD_DIR/classes:$GRIDWORKS_LIB_DIR/*"
|
CLASSPATH="$GRIDWORKS_BUILD_DIR/classes:$GRIDWORKS_LIB_DIR/*"
|
||||||
|
|
||||||
RUN_CMD="$JAVA -cp $CLASSPATH $OPTS com.metaweb.gridworks.Gridworks"
|
RUN_CMD="$JAVA -cp $CLASSPATH $OPTS com.metaweb.gridworks.Gridworks"
|
||||||
@ -349,6 +356,7 @@ while [ $# -ne 0 ] ; do
|
|||||||
-w) shift; GRIDWORKS_WEBAPP="$1"; shift; continue;;
|
-w) shift; GRIDWORKS_WEBAPP="$1"; shift; continue;;
|
||||||
-d) shift; GRIDWORKS_DATA_DIR="$1"; shift; continue;;
|
-d) shift; GRIDWORKS_DATA_DIR="$1"; shift; continue;;
|
||||||
-m) shift; GRIDWORKS_MEMORY="$1"; shift; continue;;
|
-m) shift; GRIDWORKS_MEMORY="$1"; shift; continue;;
|
||||||
|
-a) shift; add_option '-Dgridworks.autoreloading=true'; continue;;
|
||||||
--debug) shift; add_option '-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n'; continue;;
|
--debug) shift; add_option '-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n'; continue;;
|
||||||
--jmx) shift; add_option '-Dcom.sun.management.jmxremote'; continue;;
|
--jmx) shift; add_option '-Dcom.sun.management.jmxremote'; continue;;
|
||||||
-*) fail "Invalid option: $1";;
|
-*) fail "Invalid option: $1";;
|
||||||
|
@ -19,18 +19,38 @@ import org.mortbay.jetty.Connector;
|
|||||||
import org.mortbay.jetty.Server;
|
import org.mortbay.jetty.Server;
|
||||||
import org.mortbay.jetty.bio.SocketConnector;
|
import org.mortbay.jetty.bio.SocketConnector;
|
||||||
import org.mortbay.jetty.webapp.WebAppContext;
|
import org.mortbay.jetty.webapp.WebAppContext;
|
||||||
import org.mortbay.log.Log;
|
|
||||||
import org.mortbay.util.Scanner;
|
import org.mortbay.util.Scanner;
|
||||||
|
|
||||||
import com.metaweb.util.logging.IndentingLayout;
|
import com.metaweb.util.logging.IndentingLayout;
|
||||||
import com.metaweb.util.signal.SignalHandler;
|
import com.metaweb.util.signal.SignalHandler;
|
||||||
import com.metaweb.util.threads.ThreadPoolExecutorAdapter;
|
import com.metaweb.util.threads.ThreadPoolExecutorAdapter;
|
||||||
|
|
||||||
public class Gridworks extends Server {
|
public class Gridworks {
|
||||||
final static public String s_version = "1.0";
|
|
||||||
|
static private String version;
|
||||||
|
|
||||||
private static Logger root = Logger.getRootLogger();
|
private static Logger root = Logger.getRootLogger();
|
||||||
private static Logger logger = Logger.getLogger("com.metaweb.gridworks");
|
private static Logger logger = Logger.getLogger("com.metaweb.gridworks");
|
||||||
|
|
||||||
|
public static void log(String message) {
|
||||||
|
logger.info(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void info(String message) {
|
||||||
|
logger.info(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void error(String message, Throwable t) {
|
||||||
|
logger.error(message, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warn(String message) {
|
||||||
|
logger.warn(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
@ -45,46 +65,37 @@ public class Gridworks extends Server {
|
|||||||
|
|
||||||
Logger jetty_logger = Logger.getLogger("org.mortbay.log");
|
Logger jetty_logger = Logger.getLogger("org.mortbay.log");
|
||||||
jetty_logger.setLevel(Level.WARN);
|
jetty_logger.setLevel(Level.WARN);
|
||||||
|
|
||||||
|
version = Configurations.get("gridworks.version","trunk");
|
||||||
|
|
||||||
// get main configurations
|
Gridworks gridworks = new Gridworks();
|
||||||
|
|
||||||
|
gridworks.init(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(String[] args) throws Exception {
|
||||||
|
|
||||||
int port = Configurations.getInteger("gridworks.port",3333);
|
int port = Configurations.getInteger("gridworks.port",3333);
|
||||||
String host = Configurations.get("gridworks.host","127.0.0.1");
|
String host = Configurations.get("gridworks.host","127.0.0.1");
|
||||||
|
|
||||||
// create acre's server (which is a thin wrapper around Jetty)
|
GridworksServer server = new GridworksServer();
|
||||||
Gridworks server = new Gridworks(host,port);
|
server.init(host,port);
|
||||||
|
|
||||||
|
GridworksClient client = new GridworksClient();
|
||||||
|
client.init(host,port);
|
||||||
|
|
||||||
// hook up the signal handlers
|
// hook up the signal handlers
|
||||||
new ShutdownSignalHandler("TERM", server);
|
new ShutdownSignalHandler("TERM", server);
|
||||||
|
|
||||||
// start the server
|
|
||||||
server.start();
|
|
||||||
|
|
||||||
// start the browser
|
|
||||||
URI starting_url = new URI("http://" + host + ":" + port + "/");
|
|
||||||
Desktop.getDesktop().browse(starting_url);
|
|
||||||
|
|
||||||
// join this thread
|
|
||||||
server.join();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void log(String message) {
|
/* -------------- Gridworks Server ----------------- */
|
||||||
logger.info(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void error(String message, Throwable t) {
|
class GridworksServer extends Server {
|
||||||
logger.error(message, t);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void warn(String message) {
|
|
||||||
logger.warn(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------- Gridworks HTTP server ----------------- */
|
|
||||||
|
|
||||||
private ThreadPoolExecutor threadPool;
|
private ThreadPoolExecutor threadPool;
|
||||||
|
|
||||||
public Gridworks(String host, int port) throws Exception {
|
public void init(String host, int port) throws Exception {
|
||||||
|
|
||||||
int maxThreads = Configurations.getInteger("gridworks.queue.size", 10);
|
int maxThreads = Configurations.getInteger("gridworks.queue.size", 10);
|
||||||
int maxQueue = Configurations.getInteger("gridworks.queue.max_size", 50);
|
int maxQueue = Configurations.getInteger("gridworks.queue.max_size", 50);
|
||||||
long keepAliveTime = Configurations.getInteger("gridworks.queue.idle_time", 60);
|
long keepAliveTime = Configurations.getInteger("gridworks.queue.idle_time", 60);
|
||||||
@ -103,15 +114,16 @@ public class Gridworks extends Server {
|
|||||||
this.addConnector(connector);
|
this.addConnector(connector);
|
||||||
|
|
||||||
final File contextRoot = new File(Configurations.get("gridworks.webapp","webapp"));
|
final File contextRoot = new File(Configurations.get("gridworks.webapp","webapp"));
|
||||||
|
final File classRoot = new File(Configurations.get("gridworks.classes","build/classes"));
|
||||||
final String contextPath = Configurations.get("gridworks.context_path","/");
|
final String contextPath = Configurations.get("gridworks.context_path","/");
|
||||||
|
|
||||||
File webXml = new File(contextRoot, "WEB-INF/web.xml");
|
File webXml = new File(contextRoot, "WEB-INF/web.xml");
|
||||||
if (!webXml.isFile()) {
|
if (!webXml.isFile()) {
|
||||||
Log.warn("Warning: Failed to find web application. Could not find 'web.xml' at '" + webXml.getAbsolutePath() + "'");
|
Gridworks.warn("Warning: Failed to find web application. Could not find 'web.xml' at '" + webXml.getAbsolutePath() + "'");
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.info("Initializing context: '" + contextPath + "' from '" + contextRoot.getAbsolutePath() + "'");
|
Gridworks.info("Initializing context: '" + contextPath + "' from '" + contextRoot.getAbsolutePath() + "'");
|
||||||
WebAppContext context = new WebAppContext(contextRoot.getAbsolutePath(), contextPath);
|
WebAppContext context = new WebAppContext(contextRoot.getAbsolutePath(), contextPath);
|
||||||
//context.setCopyWebDir(false);
|
//context.setCopyWebDir(false);
|
||||||
//context.setDefaultsDescriptor(null);
|
//context.setDefaultsDescriptor(null);
|
||||||
@ -122,10 +134,12 @@ public class Gridworks extends Server {
|
|||||||
|
|
||||||
// Enable context autoreloading
|
// Enable context autoreloading
|
||||||
if (Configurations.getBoolean("gridworks.autoreloading",false)) {
|
if (Configurations.getBoolean("gridworks.autoreloading",false)) {
|
||||||
scanForUpdates(contextRoot, context);
|
scanForUpdates(contextRoot, classRoot, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doStop() throws Exception {
|
protected void doStop() throws Exception {
|
||||||
try {
|
try {
|
||||||
@ -138,15 +152,15 @@ public class Gridworks extends Server {
|
|||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scanForUpdates(final File contextRoot, final WebAppContext context) {
|
private void scanForUpdates(final File contextRoot, final File classRoot, final WebAppContext context) {
|
||||||
List<File> scanList = new ArrayList<File>();
|
List<File> scanList = new ArrayList<File>();
|
||||||
|
|
||||||
scanList.add(new File(contextRoot, "WEB-INF/web.xml"));
|
scanList.add(new File(contextRoot, "WEB-INF/web.xml"));
|
||||||
findFiles(".class", new File(contextRoot, "WEB-INF"), scanList);
|
findFiles(".class", new File(contextRoot, "WEB-INF"), scanList);
|
||||||
findFiles(".js", new File(contextRoot, "WEB-INF"), scanList);
|
findFiles(".class", classRoot, scanList);
|
||||||
|
|
||||||
Log.info("Starting autoreloading scanner...");
|
Gridworks.info("Starting autoreloading scanner... [class dir: " + classRoot.getAbsolutePath() + "]");
|
||||||
|
|
||||||
Scanner scanner = new Scanner();
|
Scanner scanner = new Scanner();
|
||||||
scanner.setScanInterval(Configurations.getInteger("gridworks.scanner.period",1));
|
scanner.setScanInterval(Configurations.getInteger("gridworks.scanner.period",1));
|
||||||
@ -157,10 +171,10 @@ public class Gridworks extends Server {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void filesChanged(List changedFiles) {
|
public void filesChanged(List changedFiles) {
|
||||||
try {
|
try {
|
||||||
Log.info("Stopping context: " + contextRoot.getAbsolutePath());
|
Gridworks.info("Stopping context: " + contextRoot.getAbsolutePath());
|
||||||
context.stop();
|
context.stop();
|
||||||
|
|
||||||
Log.info("Starting context: " + contextRoot.getAbsolutePath());
|
Gridworks.info("Starting context: " + contextRoot.getAbsolutePath());
|
||||||
context.start();
|
context.start();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
@ -170,8 +184,8 @@ public class Gridworks extends Server {
|
|||||||
|
|
||||||
scanner.start();
|
scanner.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
static private void findFiles(final String extension, File baseDir, final Collection<File> found) {
|
private void findFiles(final String extension, File baseDir, final Collection<File> found) {
|
||||||
baseDir.listFiles(new FileFilter() {
|
baseDir.listFiles(new FileFilter() {
|
||||||
public boolean accept(File pathname) {
|
public boolean accept(File pathname) {
|
||||||
if (pathname.isDirectory()) {
|
if (pathname.isDirectory()) {
|
||||||
@ -183,21 +197,32 @@ public class Gridworks extends Server {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------- Gridworks Client ----------------- */
|
||||||
|
|
||||||
|
class GridworksClient {
|
||||||
|
|
||||||
|
public void init(String host, int port) throws Exception {
|
||||||
|
URI starting_url = new URI("http://" + host + ":" + port + "/");
|
||||||
|
Desktop.getDesktop().browse(starting_url);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ShutdownSignalHandler extends SignalHandler {
|
class ShutdownSignalHandler extends SignalHandler {
|
||||||
|
|
||||||
private Gridworks _server;
|
private Server _server;
|
||||||
|
|
||||||
public ShutdownSignalHandler(String sigName, Gridworks server) {
|
public ShutdownSignalHandler(String sigName, Server server) {
|
||||||
super(sigName);
|
super(sigName);
|
||||||
this._server = server;
|
this._server = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean handle(String signame) {
|
public boolean handle(String signame) {
|
||||||
|
|
||||||
System.err.println("Received Signal: " + signame);
|
//System.err.println("Received Signal: " + signame);
|
||||||
|
|
||||||
// Tell the server we want to try and shutdown gracefully
|
// Tell the server we want to try and shutdown gracefully
|
||||||
// this means that the server will stop accepting new connections
|
// this means that the server will stop accepting new connections
|
||||||
|
@ -62,7 +62,7 @@ public class GridworksServlet extends HttpServlet {
|
|||||||
static protected Map<String, Command> _commands = new HashMap<String, Command>();
|
static protected Map<String, Command> _commands = new HashMap<String, Command>();
|
||||||
|
|
||||||
// timer for periodically saving projects
|
// timer for periodically saving projects
|
||||||
static protected Timer _timer = new Timer();
|
static protected Timer _timer;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
_commands.put("create-project-from-upload", new CreateProjectCommand());
|
_commands.put("create-project-from-upload", new CreateProjectCommand());
|
||||||
@ -128,6 +128,10 @@ public class GridworksServlet extends HttpServlet {
|
|||||||
|
|
||||||
ProjectManager.initialize();
|
ProjectManager.initialize();
|
||||||
|
|
||||||
|
if (_timer == null) {
|
||||||
|
_timer = new Timer();
|
||||||
|
}
|
||||||
|
|
||||||
long period = 1000 * 60 * 5; // 5 minutes
|
long period = 1000 * 60 * 5; // 5 minutes
|
||||||
_timer.scheduleAtFixedRate(new TimerTask() {
|
_timer.scheduleAtFixedRate(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -37,7 +37,7 @@ public class History implements Jsonizable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public void writeOneChange(Writer writer, Change change) throws Exception {
|
static public void writeOneChange(Writer writer, Change change) throws Exception {
|
||||||
writer.write(Gridworks.s_version); writer.write('\n');
|
writer.write(Gridworks.getVersion()); writer.write('\n');
|
||||||
writer.write(change.getClass().getName()); writer.write('\n');
|
writer.write(change.getClass().getName()); writer.write('\n');
|
||||||
|
|
||||||
Properties options = new Properties();
|
Properties options = new Properties();
|
||||||
|
@ -111,7 +111,7 @@ public class Project {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void saveToWriter(Writer writer, Properties options) throws IOException {
|
protected void saveToWriter(Writer writer, Properties options) throws IOException {
|
||||||
writer.write(Gridworks.s_version); writer.write('\n');
|
writer.write(Gridworks.getVersion()); writer.write('\n');
|
||||||
|
|
||||||
writer.write("columnModel=\n"); columnModel.save(writer, options);
|
writer.write("columnModel=\n"); columnModel.save(writer, options);
|
||||||
writer.write("history=\n"); history.save(writer, options);
|
writer.write("history=\n"); history.save(writer, options);
|
||||||
|
Loading…
Reference in New Issue
Block a user