From 7fa9d1d81266b1d642d5f268e8ecd169bc99d96c Mon Sep 17 00:00:00 2001 From: Stefano Mazzocchi Date: Fri, 25 Jun 2010 07:03:30 +0000 Subject: [PATCH] more work on the broker git-svn-id: http://google-refine.googlecode.com/svn/trunk@1035 7d457c2a-affb-35e4-300a-418c747d4874 --- broker/core/.classpath | 2 +- broker/core/WEB-INF/web.xml | 5 ++- .../gridworks/broker/GridworksBroker.java | 21 +++------- .../gridworks/broker/GridworksBrokerImpl.java | 38 ++++++------------- build.xml | 18 +++++++-- gridworks | 5 +-- .../src/com/metaweb/gridworks/Gridworks.java | 18 ++------- 7 files changed, 41 insertions(+), 66 deletions(-) diff --git a/broker/core/.classpath b/broker/core/.classpath index 18c5ef28a..1e8cc8143 100644 --- a/broker/core/.classpath +++ b/broker/core/.classpath @@ -3,7 +3,7 @@ - + diff --git a/broker/core/WEB-INF/web.xml b/broker/core/WEB-INF/web.xml index 133a9f960..63b0c075a 100644 --- a/broker/core/WEB-INF/web.xml +++ b/broker/core/WEB-INF/web.xml @@ -7,12 +7,13 @@ - gridworks-broker + Butterfly edu.mit.simile.butterfly.Butterfly + 1 - gridworks-broker + Butterfly /* diff --git a/broker/core/src/com/metaweb/gridworks/broker/GridworksBroker.java b/broker/core/src/com/metaweb/gridworks/broker/GridworksBroker.java index de358cc4b..9629dadce 100644 --- a/broker/core/src/com/metaweb/gridworks/broker/GridworksBroker.java +++ b/broker/core/src/com/metaweb/gridworks/broker/GridworksBroker.java @@ -67,16 +67,12 @@ public abstract class GridworksBroker extends ButterflyModuleImpl { protected HttpClient httpclient; - protected boolean developmentMode; - @Override public void init(ServletConfig config) throws Exception { super.init(config); httpclient = getHttpClient(); - developmentMode = Boolean.parseBoolean(config.getInitParameter("gridworks.development")); - if (developmentMode) logger.warn("Running in development mode"); } - + @Override public void destroy() throws Exception { httpclient.getConnectionManager().shutdown(); @@ -95,14 +91,14 @@ public abstract class GridworksBroker extends ButterflyModuleImpl { try { String uid = getUserId(request); - logger.debug("uid: {}", uid); + logger.debug("uid: {}", path); String pid = getParameter(request, "pid"); - logger.debug("pid: {}", pid); + logger.debug("pid: {}", path); // NOTE: conditionals should be ordered by call frequency estimate to (slightly) improve performance // we could be using a hashtable and some classes that implement the commands, but the complexity overhead // doesn't seem to justify the marginal benefit. - + if ("get_lock".equals(path)) { getLock(response, pid); } else if ("expire_locks".equals(path)) { @@ -163,11 +159,6 @@ public abstract class GridworksBroker extends ButterflyModuleImpl { @SuppressWarnings("unchecked") protected String getUserId(HttpServletRequest request) throws Exception { - // This is useful for testing - if (developmentMode) { - return getParameter(request, "uid"); - } - String oauth = request.getHeader(DELEGATED_OAUTH_HEADER); if (oauth == null) { throw new RuntimeException("The request needs to contain the '" + DELEGATED_OAUTH_HEADER + "' header set to obtain user identity via Freebase."); @@ -197,7 +188,7 @@ public abstract class GridworksBroker extends ButterflyModuleImpl { static protected String getParameter(HttpServletRequest request, String name) throws ServletException { String param = request.getParameter(name); if (param == null) { - throw new RuntimeException("request must come with a '" + name + "' parameter"); + throw new ServletException("request must come with a '" + name + "' parameter"); } return param; } @@ -215,7 +206,7 @@ public abstract class GridworksBroker extends ButterflyModuleImpl { static protected int getInteger(HttpServletRequest request, String name) throws ServletException, JSONException { return Integer.parseInt(getParameter(request, name)); } - + static protected void respondError(HttpServletResponse response, String error) throws IOException, ServletException { if (response == null) { diff --git a/broker/core/src/com/metaweb/gridworks/broker/GridworksBrokerImpl.java b/broker/core/src/com/metaweb/gridworks/broker/GridworksBrokerImpl.java index 11b6fd827..a4fedc155 100644 --- a/broker/core/src/com/metaweb/gridworks/broker/GridworksBrokerImpl.java +++ b/broker/core/src/com/metaweb/gridworks/broker/GridworksBrokerImpl.java @@ -21,7 +21,6 @@ import org.slf4j.LoggerFactory; import com.sleepycat.je.Environment; import com.sleepycat.je.EnvironmentConfig; import com.sleepycat.je.Transaction; -import com.sleepycat.persist.EntityCursor; import com.sleepycat.persist.EntityStore; import com.sleepycat.persist.PrimaryIndex; import com.sleepycat.persist.StoreConfig; @@ -41,7 +40,7 @@ public class GridworksBrokerImpl extends GridworksBroker { Timer timer; LockExpirer expirer; - + @Override public void init(ServletConfig config) throws Exception { super.init(config); @@ -50,11 +49,9 @@ public class GridworksBrokerImpl extends GridworksBroker { expirer = new LockExpirer(); timer.schedule(expirer, LOCK_EXPIRATION_CHECK_DELAY, LOCK_EXPIRATION_CHECK_DELAY); - String dataDir = config.getInitParameter("gridworks.data"); - if (dataDir == null) dataDir = "data"; - File dataPath = new File(dataDir); + File dataPath = new File("data"); // FIXME: data should be configurable; if (!dataPath.exists()) dataPath.mkdirs(); - + EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setAllowCreate(true); envConfig.setTransactional(true); @@ -76,43 +73,30 @@ public class GridworksBrokerImpl extends GridworksBroker { if (projectStore != null) { projectStore.close(); - projectById = null; } if (lockStore != null) { lockStore.close(); - lockByProject = null; } - if (timer != null) { - timer.cancel(); - timer.purge(); - timer = null; - } - if (env != null) { + env.cleanLog(); env.close(); - env = null; } } class LockExpirer extends TimerTask { public void run() { if (lockByProject != null) { - EntityCursor cursor = lockByProject.entities(); - try { - for (Lock lock = cursor.first(); lock != null; lock = cursor.next()) { - if (lock.timestamp + LOCK_DURATION < System.currentTimeMillis()) { - try { - releaseLock(null, lock.pid, lock.uid, lock.id); - } catch (Exception e) { - logger.error("Exception while expiring lock for project '" + lock.pid + "'", e); - } + for (Lock lock : lockByProject.entities()) { + if (lock.timestamp + LOCK_DURATION < System.currentTimeMillis()) { + try { + releaseLock(null, lock.pid, lock.uid, lock.id); + } catch (Exception e) { + logger.error("Exception while expiring lock for project '" + lock.pid + "'", e); } } - } finally { - cursor.close(); - } + } } } } diff --git a/build.xml b/build.xml index 8a9041558..84b09a5d1 100644 --- a/build.xml +++ b/build.xml @@ -118,6 +118,11 @@ + + + + + @@ -173,6 +178,14 @@ + + + + + + + + @@ -181,7 +194,7 @@ - + @@ -438,7 +451,7 @@ - + @@ -524,7 +537,6 @@ - diff --git a/gridworks b/gridworks index 923d8dc8c..94ee79352 100755 --- a/gridworks +++ b/gridworks @@ -585,7 +585,7 @@ run() { fi if [ -d $GRIDWORKS_CLASSES_DIR ]; then - add_option "-Dgridworks.autoreload=true -Dbutterfly.autoreload=true" + add_option "-Dgridworks.autoreloading=true" fi if $DARWIN ; then @@ -650,8 +650,7 @@ broker_run() { fi if [ -d $GRIDWORKS_CLASSES_DIR ]; then - add_option "-Dgridworks.autoreload=true -Dbutterfly.autoreload=true" - add_option "-Dgridworks.development=true" + add_option "-Dgridworks.autoreloading=true" fi add_option "-Dgridworks.webapp=broker/core" diff --git a/server/src/com/metaweb/gridworks/Gridworks.java b/server/src/com/metaweb/gridworks/Gridworks.java index 09de902e0..f02d05153 100644 --- a/server/src/com/metaweb/gridworks/Gridworks.java +++ b/server/src/com/metaweb/gridworks/Gridworks.java @@ -156,7 +156,7 @@ class GridworksServer extends Server { this.setSendServerVersion(true); // Enable context autoreloading - if (Configurations.getBoolean("gridworks.autoreload",false)) { + if (Configurations.getBoolean("gridworks.autoreloading",false)) { scanForUpdates(webapp, context); } @@ -191,7 +191,6 @@ class GridworksServer extends Server { scanList.add(new File(contextRoot, "WEB-INF/web.xml")); findFiles(".class", new File(contextRoot, "WEB-INF/classes"), scanList); - findFiles(".jar", new File(contextRoot, "WEB-INF/lib"), scanList); logger.info("Starting autoreloading scanner... "); @@ -238,19 +237,8 @@ class GridworksServer extends Server { // parameters if we set them in the webapp context upon reading the web.xml file static private void configure(WebAppContext context) throws Exception { ServletHolder servlet = context.getServletHandler().getServlet("gridworks"); - if (servlet != null) { - servlet.setInitParameter("gridworks.data", getDataDir()); - servlet.setInitOrder(1); - servlet.doStart(); - } - - servlet = context.getServletHandler().getServlet("gridworks-broker"); - if (servlet != null) { - servlet.setInitParameter("gridworks.data", getDataDir() + "/broker"); - servlet.setInitParameter("gridworks.development", Configurations.get("gridworks.development","false")); - servlet.setInitOrder(1); - servlet.doStart(); - } + servlet.setInitParameter("gridworks.data", getDataDir()); + servlet.doStart(); } static private String getDataDir() {