incubator-lokahi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tob...@apache.org
Subject svn commit: r392982 [7/25] - in /incubator/lokahi/lokahi/trunk: ./ conf/ database/ docs/ lib/ src/ src/java/ src/java/lokahi/ src/java/lokahi/core/ src/java/lokahi/core/agent/ src/java/lokahi/core/agent/callable/ src/java/lokahi/core/agent/callable/con...
Date Mon, 10 Apr 2006 16:20:11 GMT
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/ListContextCallable.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/ListContextCallable.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/ListContextCallable.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/ListContextCallable.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,41 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.callable.context;
+
+import lokahi.core.agent.interfaces.AgentTomcat;
+
+import java.util.concurrent.Callable;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: ListContextCallable.java,v 1.1 2006/03/02 19:19:39 drtobes Exp $
+ */
+public class ListContextCallable implements Callable<String[]> {
+  private AgentTomcat tc;
+
+  public ListContextCallable(AgentTomcat tc) {
+    this.tc = tc;
+  }
+
+  public String[] call() throws Exception {
+    return tc.listContexts();
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/RedeployContextCallable.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/RedeployContextCallable.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/RedeployContextCallable.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/RedeployContextCallable.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,45 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.callable.context;
+
+import lokahi.core.agent.interfaces.AgentTomcat;
+
+import java.util.concurrent.Callable;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: RedeployContextCallable.java,v 1.1 2006/03/02 19:19:39 drtobes Exp $
+ */
+public class RedeployContextCallable implements Callable<Boolean> {
+  private AgentTomcat tc;
+  private String contextName;
+  private String docBase;
+
+  public RedeployContextCallable(AgentTomcat tc, String contextName, String docBase) {
+    this.tc = tc;
+    this.contextName = contextName;
+    this.docBase = docBase;
+  }
+
+  public Boolean call() throws Exception {
+    return tc.removeContext(contextName) && tc.addContext(contextName, docBase);
+  }
+
+}
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/ReloadContextCallable.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/ReloadContextCallable.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/ReloadContextCallable.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/ReloadContextCallable.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,44 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.callable.context;
+
+import lokahi.core.agent.interfaces.AgentTomcat;
+
+import java.util.concurrent.Callable;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: ReloadContextCallable.java,v 1.1 2006/03/02 19:19:39 drtobes Exp $
+ */
+public class ReloadContextCallable implements Callable<Boolean> {
+  private AgentTomcat tc;
+  private String contextName;
+
+  public ReloadContextCallable(AgentTomcat tc, String contextName) {
+    this.tc = tc;
+    this.contextName = contextName;
+  }
+
+  public Boolean call() throws Exception {
+    return tc.reloadContext(contextName);
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/RemoveContextCallable.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/RemoveContextCallable.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/RemoveContextCallable.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/RemoveContextCallable.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,44 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.callable.context;
+
+import lokahi.core.agent.interfaces.AgentTomcat;
+
+import java.util.concurrent.Callable;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: RemoveContextCallable.java,v 1.1 2006/03/02 19:19:39 drtobes Exp $
+ */
+public class RemoveContextCallable implements Callable<Boolean> {
+  private AgentTomcat tc;
+  private String contextName;
+
+  public RemoveContextCallable(AgentTomcat tc, String contextName) {
+    this.tc = tc;
+    this.contextName = contextName;
+  }
+
+  public Boolean call() throws Exception {
+    return tc.removeContext(contextName);
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/StartContextCallable.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/StartContextCallable.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/StartContextCallable.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/StartContextCallable.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,43 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.callable.context;
+
+import lokahi.core.agent.interfaces.AgentTomcat;
+
+import java.util.concurrent.Callable;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: StartContextCallable.java,v 1.1 2006/03/02 19:19:39 drtobes Exp $
+ */
+public class StartContextCallable implements Callable<Boolean> {
+  private AgentTomcat tc;
+  private String contextName;
+
+  public StartContextCallable(AgentTomcat tc, String contextName) {
+    this.tc = tc;
+    this.contextName = contextName;
+  }
+
+  public Boolean call() throws Exception {
+    return tc.startContext(contextName);
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/StopContextCallable.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/StopContextCallable.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/StopContextCallable.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/context/StopContextCallable.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,44 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.callable.context;
+
+import lokahi.core.agent.interfaces.AgentTomcat;
+
+import java.util.concurrent.Callable;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: StopContextCallable.java,v 1.1 2006/03/02 19:19:39 drtobes Exp $
+ */
+public class StopContextCallable implements Callable<Boolean> {
+  private AgentTomcat tc;
+  private String contextName;
+
+  public StopContextCallable(AgentTomcat tc, String contextName) {
+    this.tc = tc;
+    this.contextName = contextName;
+  }
+
+  public Boolean call() throws Exception {
+    return tc.stopContext(contextName);
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/tomcat/RestartTomcatCallable.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/tomcat/RestartTomcatCallable.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/tomcat/RestartTomcatCallable.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/tomcat/RestartTomcatCallable.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,49 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.callable.tomcat;
+
+import lokahi.core.agent.interfaces.AgentTomcat;
+
+import java.util.concurrent.Callable;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: RestartTomcatCallable.java,v 1.1 2006/03/02 19:19:39 drtobes Exp $
+ */
+public class RestartTomcatCallable implements Callable<Boolean> {
+  private AgentTomcat tc;
+  private int flowLevel;
+
+  public RestartTomcatCallable(AgentTomcat tc, int flowLevel) {
+    this.tc = tc;
+    this.flowLevel = flowLevel;
+  }
+
+  public Boolean call() throws Exception {
+    boolean ret = false;
+    Callable<Boolean> c = new StopTomcatCallable(tc, flowLevel);
+    if (c.call()) {
+      c = new StartTomcatCallable(tc);
+      ret = c.call();
+    }
+    return ret;
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/tomcat/StartTomcatCallable.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/tomcat/StartTomcatCallable.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/tomcat/StartTomcatCallable.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/tomcat/StartTomcatCallable.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,46 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.callable.tomcat;
+
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.agent.util.ProcessFactory;
+
+import java.io.File;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: StartTomcatCallable.java,v 1.1 2006/03/02 19:19:39 drtobes Exp $
+ */
+public class StartTomcatCallable implements Callable<Boolean> {
+  private AgentTomcat tc;
+
+  public StartTomcatCallable(AgentTomcat tc) {
+    this.tc = tc;
+  }
+
+  public Boolean call() throws Exception {
+    ProcessBuilder pb = new ProcessBuilder(tc.getStartCommand());
+    Map<String, String> env = pb.environment();
+    env.clear();
+    env.putAll(tc.getEnv());
+    pb.directory(new File("/"));
+    Process p = pb.start();
+    ProcessFactory.addProcess(tc, p);
+    return true;
+  }
+}
\ No newline at end of file

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/tomcat/StopTomcatCallable.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/tomcat/StopTomcatCallable.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/tomcat/StopTomcatCallable.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/callable/tomcat/StopTomcatCallable.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,47 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.callable.tomcat;
+
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.agent.util.ProcessFactory;
+
+import java.util.concurrent.Callable;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: StopTomcatCallable.java,v 1.1 2006/03/02 19:19:39 drtobes Exp $
+ */
+public class StopTomcatCallable implements Callable<Boolean> {
+  private AgentTomcat tc;
+  private int flowLevel;
+
+  public StopTomcatCallable(AgentTomcat tc, int flowLevel) {
+    this.tc = tc;
+    this.flowLevel = flowLevel;
+  }
+
+  public Boolean call() throws Exception {
+    Process p = ProcessFactory.getProcess(tc);
+    p.destroy();
+    ProcessFactory.removeProcess(tc);
+    return true;
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/AgentJob.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/AgentJob.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/AgentJob.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/AgentJob.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,252 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.dao;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.state.State;
+import lokahi.core.common.collection.TMCCollectionImpl;
+import lokahi.core.common.collection.TMCDataStore;
+import lokahi.core.common.interfaces.Collectable;
+import lokahi.core.common.interfaces.Dao;
+import lokahi.core.common.util.PropertiesFile;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.Date;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: AgentJob.java,v 1.4 2006/03/07 20:18:45 drtobes Exp $
+ */
+public class AgentJob implements Dao, Collectable {
+  private static final TMCDataStore<AgentJob> broker = new TMCDataStore<AgentJob>();
+  private int pk;
+  private int type;
+  private String name;
+  private String parentName;
+  private State status;
+  private Function function;
+  private String[] options;
+
+  private String returnTo;
+  private String returnEndpoint;
+  private String returnMethod;
+
+  private Date runTime;
+  private String attachment;
+  private String result;
+
+  public int getPk() {
+    return pk;
+  }
+
+  private void setType(int type) {
+    this.type = type;
+  }
+
+  public void setType(TaskType type) {
+    this.type = type.getId();
+  }
+
+  public TaskType getType() {
+    return TaskType.getType(type);
+  }
+
+  public void setPk(int pk) {
+    this.pk = pk;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getAttachment() {
+    return attachment;
+  }
+
+  public void setAttachment(String attachment) {
+    this.attachment = attachment;
+  }
+
+  public String[] getOptions() {
+    return options;
+  }
+
+  public void setOptions(String[] options) {
+    this.options = options;
+  }
+
+  public String getParentName() {
+    return parentName;
+  }
+
+  public void setParentName(String parentName) {
+    this.parentName = parentName;
+  }
+
+  public String getReturnTo() {
+    return returnTo;
+  }
+
+  public void setReturnTo(String returnTo) {
+    this.returnTo = returnTo;
+  }
+
+  public String getReturnEndpoint() {
+    return returnEndpoint;
+  }
+
+  public void setReturnEndpoint(String returnEndpoint) {
+    this.returnEndpoint = returnEndpoint;
+  }
+
+  public String getReturnMethod() {
+    return returnMethod;
+  }
+
+  public void setReturnMethod(String returnMethod) {
+    this.returnMethod = returnMethod;
+  }
+
+  public Date getRunTime() {
+    return runTime;
+  }
+
+  public void setRunTime(Date runTime) {
+    this.runTime = runTime;
+  }
+
+  public Function getFunction() {
+    return function;
+  }
+
+  public void setFunction(Function function) {
+    this.function = function;
+  }
+
+  public String getResult() {
+    return result;
+  }
+
+  public void setResult(String result) {
+    this.result = result;
+  }
+
+  public State getStatus() {
+    return status;
+  }
+
+  public void setStatus(State status) {
+    this.status = status;
+  }
+
+  public AgentJob() {
+  }
+
+  public AgentJob(int type, String name, String parentName, int stateId, int functionId, String options,
+                  String returnTo, String returnEndpoint, String returnMethod, Date runtime, String attachment,
+                  String result) {
+    this.setType(type);
+    this.setName(name);
+    this.setParentName(parentName);
+    this.setStatus(State.getState(stateId));
+    this.setFunction(Function.getFunction(functionId));
+    this.setOptions(options.split(PropertiesFile.getConstantValue("agent.delim.options")));
+    this.setReturnTo(returnTo);
+    this.setReturnEndpoint(returnEndpoint);
+    this.setReturnMethod(returnMethod);
+    this.setRunTime(runtime);
+    this.setAttachment(attachment);
+    this.setResult(result);
+  }
+
+  public AgentJob(int pk, int type, String name, String parentName, int stateId, int functionId, String options,
+                  String returnTo, String returnEndpoint, String returnMethod, Date runtime, String attachment,
+                  String result) {
+    this.setPk(pk);
+    this.setType(type);
+    this.setName(name);
+    this.setParentName(parentName);
+    this.setStatus(State.getState(stateId));
+    this.setFunction(Function.getFunction(functionId));
+    this.setOptions(options.split(PropertiesFile.getConstantValue("agent.delim.options")));
+    this.setReturnTo(returnTo);
+    this.setReturnEndpoint(returnEndpoint);
+    this.setReturnMethod(returnMethod);
+    this.setRunTime(runtime);
+    this.setAttachment(attachment);
+    this.setResult(result);
+  }
+
+  public static AgentJob store(AgentJob j) throws SQLException {
+    j.setPk(broker.store(j));
+    return j;
+  }
+
+  public static Collection<AgentJob> getJobs(State s) {
+    Collection<AgentJob> c = new TMCCollectionImpl<AgentJob>();
+    for (AgentJob j : broker.values()) {
+      if (j.getStatus().equals(s)) {
+        c.add(j);
+      }
+    }
+    return c;
+  }
+
+  public void update() throws SQLException {
+    broker.add(this);
+  }
+
+  public AgentJob fillObject(ResultSet r) throws SQLException {
+    return new AgentJob(
+        r.getInt("pk"),
+        r.getInt("type"),
+        r.getString("name"),
+        r.getString("parentName"),
+        r.getInt("status"),
+        r.getInt("function_id"),
+        r.getString("options"),
+        r.getString("returnTo"),
+        r.getString("returnEndpoint"),
+        r.getString("returnMethod"),
+        r.getDate("runTime"),
+        r.getString("attachment"),
+        r.getString("result")
+    );
+  }
+
+  private static String join(String[] arr, String delim) {
+    StringBuilder sb = new StringBuilder();
+    if (delim == null) delim = "";
+    if (arr != null)
+      for (String st : arr) {
+        sb.append(st);
+        sb.append(delim);
+      }
+    return sb.toString();
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/ProcessMonitor.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/ProcessMonitor.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/ProcessMonitor.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/ProcessMonitor.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,76 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.dao;
+
+import lokahi.core.agent.interfaces.Monitor;
+import lokahi.core.agent.interfaces.MonitoredProcess;
+import lokahi.core.agent.util.CommandLineProcess;
+import org.apache.log4j.Logger;
+
+import java.io.IOException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: ProcessMonitor.java,v 1.1 2006/03/02 19:19:40 drtobes Exp $
+ */
+public class ProcessMonitor implements Monitor {
+  static final Logger logger = Logger.getLogger(ProcessMonitor.class);
+  private MonitoredProcess process;
+  private boolean shouldRestart;
+
+  ProcessMonitor() {
+  }
+
+  public ProcessMonitor(MonitoredProcess p) {
+    this.process = p;
+  }
+
+  public void check() {
+    shouldRestart = false;
+    int pid = process.getPid();
+    StringBuilder sb = new StringBuilder();
+    sb.append("kill -s 0 ");
+    sb.append(pid);
+    CommandLineProcess clp = new CommandLineProcess(sb.toString());
+    try {
+      clp.start();
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    shouldRestart = clp.getExitCode() == 0;
+  }
+
+  public void refresh() {//TODO check the process, against the DB, and blaugh
+    shouldRestart = false;
+
+  }
+
+  public boolean shouldRestartProc() {
+    return shouldRestart;
+  }
+
+  public MonitoredProcess getProcess() {
+    return process;
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/TaskType.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/TaskType.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/TaskType.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/TaskType.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,56 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.dao;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TaskType.java,v 1.1 2006/03/02 19:19:40 drtobes Exp $
+ */
+public enum TaskType {
+  SCHEDULED_JOB(1),
+  MONITOR(2),
+  COMMAND_LINE_JOB(3);
+  private final int id;
+
+  TaskType(int id) {
+    this.id = id;
+  }
+
+  public int getId() {
+    return id;
+  }
+
+  public static TaskType getType(int reqId) {
+    TaskType t;
+    switch (reqId) {
+      case 2:
+        t = MONITOR;
+        break;
+      case 3:
+        t = COMMAND_LINE_JOB;
+        break;
+      default:
+        t = SCHEDULED_JOB;
+    }
+    return t;
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/TomcatDao.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/TomcatDao.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/TomcatDao.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/TomcatDao.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,35 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.dao;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TomcatDao.java,v 1.1 2006/03/02 19:19:40 drtobes Exp $
+ */
+public class TomcatDao {
+  private String name;
+  private int httpPort;
+  private boolean isJMX;
+  private String javaHome;
+  private String vmArgs;
+  private String standardOutLog;
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/URLMonitor.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/URLMonitor.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/URLMonitor.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/dao/URLMonitor.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,127 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.dao;
+
+import lokahi.core.agent.interfaces.Monitor;
+import lokahi.core.agent.interfaces.MonitoredProcess;
+
+import java.net.URL;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: URLMonitor.java,v 1.1 2006/03/02 19:19:40 drtobes Exp $
+ */
+public class URLMonitor implements Monitor {
+  private int pk;
+  private URL url;
+  private MonitoredProcess process;
+  private String contentToMatch;
+  private boolean restartOnFailure;
+  private int failures;
+  private int failuresTillRestart;
+  private int sleepInterval;
+
+  public int getPk() {
+    return pk;
+  }
+
+  public void setPk(int pk) {
+    this.pk = pk;
+  }
+
+  public URL getUrl() {
+    return url;
+  }
+
+  public void setUrl(URL url) {
+    this.url = url;
+  }
+
+  public String getContentToMatch() {
+    return contentToMatch;
+  }
+
+  public void setContentToMatch(String contentToMatch) {
+    this.contentToMatch = contentToMatch;
+  }
+
+  public boolean isRestartOnFailure() {
+    return restartOnFailure;
+  }
+
+  public void setRestartOnFailure(boolean restartOnFailure) {
+    this.restartOnFailure = restartOnFailure;
+  }
+
+  public MonitoredProcess getProcess() {
+    return process;
+  }
+
+  public int getFailures() {
+    return failures;
+  }
+
+  public void setFailures(int failures) {
+    this.failures = failures;
+  }
+
+  public int getFailuresTillRestart() {
+    return failuresTillRestart;
+  }
+
+  public void setFailuresTillRestart(int failuresTillRestart) {
+    this.failuresTillRestart = failuresTillRestart;
+  }
+
+  public int getSleepInterval() {
+    return sleepInterval;
+  }
+
+  public void setSleepInterval(int sleepInterval) {
+    this.sleepInterval = sleepInterval;
+  }
+
+  public URLMonitor() {
+  }
+
+  public URLMonitor(int pk, URL url, String contentToMatch, boolean restartOnFailure, int failuresTillRestart, MonitoredProcess p) {
+    this.setPk(pk);
+    this.setUrl(url);
+    this.setContentToMatch(contentToMatch);
+    this.setRestartOnFailure(restartOnFailure);
+    this.setFailuresTillRestart(failuresTillRestart);
+    this.process = p;
+  }
+
+  public void check() {
+    //create a job to check the URL if one isn't already here, and it's time to run.
+    //if one is here check to see if it's finished.
+    //if it's done, collect the result.
+  }
+
+  public void refresh() { //TODO finish this.
+
+  }
+
+  public boolean shouldRestartProc() {
+    return failures >= failuresTillRestart;
+  }
+
+}
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/interfaces/AgentTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/interfaces/AgentTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/interfaces/AgentTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/interfaces/AgentTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,46 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.interfaces;
+
+import lokahi.core.agent.dao.TaskType;
+import lokahi.core.agent.util.TMCTaskException;
+
+import java.util.concurrent.ExecutionException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: AgentTask.java,v 1.1 2006/03/02 19:19:40 drtobes Exp $
+ */
+public interface AgentTask {
+  String getResult() throws ExecutionException, InterruptedException, TMCTaskException;
+
+  int getJobId();
+
+  boolean isDone();
+
+  boolean cancel(boolean mayInterruptIfRunning);
+
+  boolean isCanceled();
+
+  Runnable getRunnable();
+
+  TaskType getType();
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/interfaces/AgentTomcat.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/interfaces/AgentTomcat.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/interfaces/AgentTomcat.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/interfaces/AgentTomcat.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,55 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.interfaces;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: AgentTomcat.java,v 1.1 2006/03/02 19:19:40 drtobes Exp $
+ */
+public interface AgentTomcat extends MonitoredProcess {
+  boolean startContext(String context);
+
+  boolean stopContext(String context);
+
+  boolean reloadContext(String context);
+
+  boolean addContext(String path, String docBase);
+
+  String[] listContexts();
+
+  boolean removeContext(String context);
+
+  String getSessions(String context);
+
+  void setName(String name);
+
+  void setJavaOptions(String options);
+
+  void setEnvironment(String env);
+
+  void setJavaHome(String javaHome);
+
+  void setStartClass(String startClass);
+
+  void setStandardOutLog(String logLocation);
+
+  String getStartCommand();
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/interfaces/Monitor.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/interfaces/Monitor.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/interfaces/Monitor.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/interfaces/Monitor.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,36 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.interfaces;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Monitor.java,v 1.1 2006/03/02 19:19:40 drtobes Exp $
+ */
+public interface Monitor {
+  void check();
+
+  void refresh();
+
+  boolean shouldRestartProc();
+
+  MonitoredProcess getProcess();
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/interfaces/MonitoredProcess.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/interfaces/MonitoredProcess.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/interfaces/MonitoredProcess.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/interfaces/MonitoredProcess.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,50 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.interfaces;
+
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.api.state.State;
+
+import java.sql.SQLException;
+import java.util.Map;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: MonitoredProcess.java,v 1.2 2006/03/06 22:31:42 drtobes Exp $
+ */
+public interface MonitoredProcess {
+  Map<String, String> getEnv();
+
+  int getPid();
+
+  String getStartClass();
+
+  boolean shouldRestart();
+
+  AgentJob localRestart();
+
+  State getState();
+
+  void setState(State s);
+
+  void update() throws SQLException;
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/jmx/JMXConnect.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/jmx/JMXConnect.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/jmx/JMXConnect.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/jmx/JMXConnect.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,249 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+/**
+ *
+ */
+package lokahi.core.agent.jmx;
+
+import lokahi.core.agent.dao.TaskType;
+import lokahi.core.agent.interfaces.AgentTask;
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.agent.util.TMCTaskException;
+import org.apache.log4j.Logger;
+import sun.jvmstat.monitor.HostIdentifier;
+import sun.jvmstat.monitor.MonitorException;
+import sun.jvmstat.monitor.MonitoredHost;
+import sun.jvmstat.monitor.MonitoredVmUtil;
+import sun.jvmstat.monitor.VmIdentifier;
+import sun.management.ConnectorAddressLink;
+import sun.management.counter.perf.InstrumentationException;
+
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanServerConnection;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: JMXConnect.java,v 1.1 2006/03/02 19:19:41 drtobes Exp $
+ * @deprecated
+ */
+public class JMXConnect {
+  static final Logger logger = Logger.getLogger(JMXConnect.class);
+
+  private JMXConnect() {
+  }
+
+  /** @deprecated  */
+  public static ArrayList<JMXVirtualMachine> getAllJMXVirtualMachines() {
+    //System.out.println("Entering method");
+    MonitoredHost monitoredhost;
+    ArrayList<JMXVirtualMachine> arraylist;
+    Iterator iterator;
+    Set set;
+    try {
+      //Monitoredhost object, java to OS layer
+      //System.out.println("About to get MonitoredHost method");
+      monitoredhost = MonitoredHost.getMonitoredHost(new HostIdentifier((String) "localhost"));
+      //Set of active vms on host
+      set = monitoredhost.activeVms();
+      //System.out.println("Number of active VMs on " + set.size());
+    } catch (URISyntaxException urisyntaxexception) {
+      throw new InternalError(urisyntaxexception.getMessage());
+    } catch (MonitorException monitorexception) {
+      throw new InternalError(monitorexception.getMessage());
+    }
+    arraylist = new ArrayList<JMXVirtualMachine>();
+    iterator = set.iterator();
+    Object obj = null;
+    int i;
+    String jmxurl = null;
+    while (iterator.hasNext()) {
+      obj = iterator.next();
+      i = Integer.parseInt(obj.toString());
+      try {
+        jmxurl = ConnectorAddressLink.importFrom(i);
+      } catch (InstrumentationException ie) {
+        //System.out.println("Older JVM running");
+        //Older JDK , ignore this exception
+      } catch (IOException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+      if (jmxurl != null)
+        try {
+          VmIdentifier vmidentifier = new VmIdentifier(Integer.toString(i));
+          String clarg = MonitoredVmUtil.commandLine(monitoredhost.getMonitoredVm(vmidentifier));
+          String vmArgs = MonitoredVmUtil.jvmArgs(monitoredhost.getMonitoredVm(vmidentifier));
+          arraylist.add(getVirtualMachine(i, clarg, vmArgs));
+        } catch (Exception e) {
+          if (logger.isInfoEnabled()) {
+            logger.info("Exception: " + e.getMessage());
+          }
+        }
+    } // end while
+    return arraylist;
+  }
+
+  /** @deprecated  */
+  public static JMXVirtualMachine getVirtualMachine(int pid, String commandLineArgs, String vmArgs) {
+    JMXVirtualMachine ret = null;
+    if ("org.apache.catalina.startup.Bootstrap start".equals(commandLineArgs))
+      ret = new JMXTomcat(pid, commandLineArgs, vmArgs);
+    return ret;
+  }
+
+  /**
+   * @param pid
+   *
+   * @return
+   * @throws IOException
+   * @deprecated
+   */
+  public static String getJMXUrl(int pid) throws IOException {
+    return ConnectorAddressLink.importFrom(pid);
+  }
+
+  /**
+   * @param info
+   *
+   * @deprecated
+   */
+  public static void getMBeanAttributes(MBeanInfo info) {
+    StringBuilder sb = new StringBuilder("Attributes");
+    MBeanAttributeInfo[] attributes = info.getAttributes();
+    if (attributes.length > 0) {
+      for (MBeanAttributeInfo info2 : attributes) {
+        sb.append(' ');
+        sb.append(info2.getName());
+        sb.append(": ");
+        sb.append(info2.getDescription());
+      }
+      if (logger.isDebugEnabled()) {
+        logger.debug("sb.toString()=" + sb.toString());
+      }
+    }
+  }
+
+  /**
+   * @param info
+   *
+   * @deprecated
+   */
+  public static void getMBeanOperations(MBeanInfo info) {
+    StringBuilder sb = new StringBuilder("Attributes");
+    MBeanOperationInfo[] operations = info.getOperations();
+    if (operations.length > 0) {
+      for (MBeanOperationInfo info2 : operations) {
+        sb.append(' ');
+        sb.append(info2.getName());
+        sb.append(": ");
+        sb.append(info2.getDescription());
+        sb.append(' ');
+        sb.append(info2.getReturnType());
+      }
+      if (logger.isDebugEnabled()) {
+        logger.debug("sb.toString()=" + sb.toString());
+      }
+    }
+  }
+
+  /**
+   * @param JMXurl
+   *
+   * @return
+   * @throws IOException
+   * @deprecated
+   */
+  public static MBeanServerConnection connect(String JMXurl) throws IOException {
+    JMXServiceURL address = new JMXServiceURL(JMXurl);
+    Map creationEnvironment = null;
+    //Create the JMXCconnectorServer
+    JMXConnector cntor = JMXConnectorFactory.newJMXConnector(address, creationEnvironment);
+    //      The connection environment map, null in this case
+    //      May contain - for example - user's credentials
+    Map connectionEnvironment = null;
+    //      Connect
+    cntor.connect(connectionEnvironment);
+    //      Obtain a "stub" for the remote MBeanServer
+    MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
+
+    return mbsc;
+  }
+
+  /**
+   * @param pid
+   *
+   * @return
+   * @throws IOException
+   * @deprecated
+   */
+  public static MBeanServerConnection connect(int pid) throws IOException {
+    return connect(getJMXUrl(pid));
+  }
+
+  /** @deprecated  */
+  public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, InstantiationException, TMCTaskException, ExecutionException, InterruptedException {
+//    System.out.println("args[0] = " + args[0]);
+//    System.out.println("args[1] = " + args[1]);
+    int httpPort = Integer.parseInt(args[0]);
+    String function = args[1];
+    AgentTask task = null;
+    AgentTomcat t = null;
+    Class c = Class.forName("tmc.agent.task." + function + "Task");
+    Constructor[] cs = c.getConstructors();
+    if (cs.length == 1) {
+      String name = "Agent" + (httpPort - 2);
+      ArrayList<JMXVirtualMachine> jmxvm = getAllJMXVirtualMachines();
+      for (JMXVirtualMachine jvm : jmxvm) {
+        if (jvm instanceof JMXTomcat && name.equals(jvm.getVmName())) {
+          t = (JMXTomcat) jvm;
+        }
+      }
+      Constructor cons = cs[0];
+      Class[] params = cons.getParameterTypes();
+      if (t != null) {
+        if (params.length == 3) {
+          task = (AgentTask) cons.newInstance(111, TaskType.COMMAND_LINE_JOB, t);
+        } else if (params.length == 4) {
+          task = (AgentTask) cons.newInstance(111, TaskType.COMMAND_LINE_JOB, t, args[2]);
+        } else if (params.length == 5) {
+          task = (AgentTask) cons.newInstance(111, TaskType.COMMAND_LINE_JOB, t, args[2], args[3]);
+        }
+        task.getRunnable().run();
+        System.out.println(task.getResult());
+      }
+    }
+  }
+
+}
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/jmx/JMXTomcat.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/jmx/JMXTomcat.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/jmx/JMXTomcat.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/jmx/JMXTomcat.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,432 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.jmx;
+
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.api.state.State;
+import org.apache.log4j.Logger;
+
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanServerConnection;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: JMXTomcat.java,v 1.2 2006/03/06 22:31:43 drtobes Exp $
+ */
+public class JMXTomcat extends JMXVirtualMachine implements AgentTomcat {
+  static final Logger logger = Logger.getLogger(JMXTomcat.class);
+  private int pk;
+  private int httpPort;
+  private String javaHome;
+  private boolean shouldRestart;
+  private String standardOutLog;
+  private State state;
+  private String name;
+  private HashMap<String, String> env = new HashMap<String, String>();
+
+  public void setEnvironment(String s) {
+    while (!"".equals(s.trim())) {
+      env.put(s.substring(0, s.indexOf('=') - 1), s.substring(s.indexOf('='), s.indexOf(';') - 1));
+      s = s.substring(s.indexOf(';'));
+    }
+  }
+
+  public int getPk() {
+    return pk;
+  }
+
+  public void setPk(int pk) {
+    this.pk = pk;
+  }
+
+  public State getState() {
+    return state;
+  }
+
+  public void setState(State s) {
+    this.state = s;
+  }
+
+  public int getHttpPort() {
+    return httpPort;
+  }
+
+  public void setHttpPort(int httpPort) {
+    this.httpPort = httpPort;
+  }
+
+  public String getJavaHome() {
+    return javaHome;
+  }
+
+  public void setJavaHome(String javaHome) {
+    this.javaHome = javaHome;
+  }
+
+  public boolean shouldRestart() {
+    return shouldRestart;
+  }
+
+  public void setShouldRestart(boolean shouldRestart) {
+    this.shouldRestart = shouldRestart;
+  }
+
+  public String getStandardOutLog() {
+    return standardOutLog;
+  }
+
+  public void setStandardOutLog(String standardOutLog) {
+    this.standardOutLog = standardOutLog;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public JMXTomcat() {
+  }
+
+  public JMXTomcat(int id, String command, String args) {//todo rework this
+    this.setVmPid(id);
+    this.setStartClass(command);
+    this.setJavaOptions(args);
+    buildVmName();
+  }
+
+  protected JMXTomcat(int pid) {//todo rework this
+    initFromProcessId(pid);
+  }
+
+  protected HashMap<String, ObjectName> getContexts() throws MalformedObjectNameException, ReflectionException, IOException, InstanceNotFoundException, MBeanException, AttributeNotFoundException {
+    HashMap<String, ObjectName> contexts = new HashMap<String, ObjectName>();
+    if (this.getMbsc() != null) {
+      ObjectName[] objarray = (ObjectName[]) this.getMbsc().getAttribute(this.getHost(), "children");
+      //Place the contexts and the corresponding ObjectName into a HashMap [String,ObjectName]
+      //Example ["/jsp-examples",Tomcat8080:j2eeType=WebModule,name=//localhost/jsp-examples,J2EEApplication=none,J2EEServer=none]
+      for (ObjectName name : objarray) {
+        contexts.put(name.getCanonicalName().substring(name.getCanonicalName().lastIndexOf("//localhost")), name);
+        //System.out.println(name.getCanonicalName().substring(name.getCanonicalName().lastIndexOf("/")));
+      }
+    }
+    return contexts;
+  }
+
+  protected ObjectName getContextObjectName(String context) throws MalformedObjectNameException {
+    StringBuilder sb = new StringBuilder();
+    sb.append(this.getVmName());
+    sb.append(":j2eeType=WebModule,name=//localhost");
+    sb.append(checkContextName(context));
+    sb.append(",J2EEApplication=none,J2EEServer=none");
+    ObjectName objName = new ObjectName(sb.toString());
+    return objName;
+  }
+
+  protected ObjectName getContextManagerName(String context) throws MalformedObjectNameException {
+    StringBuilder sb = new StringBuilder();
+    sb.append(this.getVmName());
+    sb.append(":type=Manager,path=");
+    sb.append(checkContextName(context));
+    sb.append(",host=localhost");
+    ObjectName objName = new ObjectName(sb.toString());
+    return objName;
+  }
+
+  protected static String checkContextName(String name) {
+    if (!name.trim().startsWith("/")) name = new StringBuilder(name.trim()).insert(0, '/').toString();
+    return name.trim();
+  }
+
+  public boolean startContext(String context) {
+    return this.invokeContextVoidMethod(context, "start", null, null);
+  }
+
+  public boolean stopContext(String context) {
+    return this.invokeContextVoidMethod(context, "stop", null, null);
+  }
+
+  public boolean reloadContext(String context) {
+    return this.invokeContextVoidMethod(context, "reload", null, null);
+  }
+
+  public boolean addContext(String path, String docBase) {
+    boolean ret = false;
+    try {
+      if (!this.getContexts().keySet().contains(checkContextName(path)))
+        ret = this.invokeVoidMethod(this.getCatalinaMBean(), "createStandardContext", new Object[]{this.getHost().toString(), checkContextName(path), docBase}, new String[]{"String", "String", "String"});
+    } catch (MalformedObjectNameException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (ReflectionException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (InstanceNotFoundException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (MBeanException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (AttributeNotFoundException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return ret;
+  }
+
+  public String[] listContexts() {
+    String[] ret = {"Error"};
+    try {
+      ret = this.getContexts().keySet().toArray(new String[]{});
+    } catch (MalformedObjectNameException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (ReflectionException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (InstanceNotFoundException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (MBeanException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (AttributeNotFoundException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return ret;
+  }
+
+  public boolean removeContext(String context) {
+    boolean ret = false;
+    try {
+      ret = this.invokeVoidMethod(this.getCatalinaMBean(), "removeContext", new Object[]{this.getContextObjectName(context).toString()}, new String[]{"String"});
+    } catch (MalformedObjectNameException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return ret;
+  }
+
+  public String getSessions(String context) {
+    String ret = "";
+    try {
+      ret = (String) this.getMbsc().invoke(this.getContextManagerName(context), "listSessionIds", null, null);
+    } catch (InstanceNotFoundException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (MBeanException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (ReflectionException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (MalformedObjectNameException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return ret;
+  }
+
+  protected void buildVmName() {
+    try {
+      ObjectName service = new ObjectName("Catalina:type=Server");
+      ObjectName[] serviceName = (ObjectName[]) this.getMbsc().getAttribute(service, "serviceNames");
+      this.setVmName(serviceName[0].getDomain());
+    } catch (ReflectionException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (InstanceNotFoundException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      this.setVmName("No Name Exists");
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (MBeanException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (AttributeNotFoundException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (MalformedObjectNameException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+  }
+
+  private ObjectName getHost() throws MalformedObjectNameException {
+    StringBuilder sb = new StringBuilder();
+    sb.append(this.getVmName());
+    sb.append(":type=Host,host=localhost");
+    ObjectName objName = new ObjectName(sb.toString());
+    return objName;
+  }
+
+  private ObjectName getCatalinaMBean() throws MalformedObjectNameException {
+    ObjectName objName = new ObjectName("Catalina:type=MBeanFactory");
+    return objName;
+  }
+
+  private boolean invokeContextVoidMethod(String contextName, String method, Object[] params, String[] signature) {
+    boolean ret = false;
+    try {
+      ret = this.invokeVoidMethod(this.getContextObjectName(contextName), method, params, signature);
+    } catch (MalformedObjectNameException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return ret;
+  }
+
+  public String getStartCommand() {
+    return javaHome + "/bin/java " + this.getJavaOptions() + ' ' + this.getStartClass() + " start >>" + standardOutLog;
+  }
+
+  private boolean invokeVoidMethod(ObjectName obj, String method, Object[] params, String[] signature) {
+    boolean ret = false;
+    try {
+      MBeanServerConnection mbsc = this.getMbsc();
+      if (mbsc != null) {
+        mbsc.invoke(obj, method, params, signature);
+        ret = true;
+      }
+    } catch (InstanceNotFoundException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (MBeanException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (ReflectionException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (NullPointerException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return ret;
+
+  }
+
+  public int getActiveSessions(String context) {
+    int ret = -1;
+    try {
+      if (this.getMbsc() != null) {
+        ret = (Integer) this.getMbsc().getAttribute(this.getContextManagerName(context), "activeSessions");
+      }
+    } catch (InstanceNotFoundException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (MalformedObjectNameException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (MBeanException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (ReflectionException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (NullPointerException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (AttributeNotFoundException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return ret;
+  }
+
+  public Map<String, String> getEnv() {
+    return env;
+  }
+
+  public AgentJob localRestart() { //TODO finish this.
+    return null;
+  }
+
+  public void update() throws SQLException {//TODO finish this.
+
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/jmx/JMXVirtualMachine.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/jmx/JMXVirtualMachine.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/jmx/JMXVirtualMachine.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/jmx/JMXVirtualMachine.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,198 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.jmx;
+
+import lokahi.core.agent.interfaces.MonitoredProcess;
+import org.apache.log4j.Logger;
+import sun.jvmstat.monitor.HostIdentifier;
+import sun.jvmstat.monitor.MonitorException;
+import sun.jvmstat.monitor.MonitoredHost;
+import sun.jvmstat.monitor.MonitoredVmUtil;
+import sun.jvmstat.monitor.VmIdentifier;
+import sun.management.ConnectorAddressLink;
+import sun.management.counter.perf.InstrumentationException;
+
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanServerConnection;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+import java.io.IOException;
+import java.net.URISyntaxException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: JMXVirtualMachine.java,v 1.1 2006/03/02 19:19:41 drtobes Exp $
+ */
+public abstract class JMXVirtualMachine implements MonitoredProcess {
+  static final Logger logger = Logger.getLogger(JMXVirtualMachine.class);
+  private int vmPid;  // the pid of the vm.
+  private String startClass;  // the startClass line javaOptions to the vm.  example "org.apache.catalina.Bootstrap start"
+  private String javaOptions;  // the -D params passed to java
+  private String vmName;  // the name of the vm?  do we want this here?
+  private MBeanServerConnection mbsc;  // the MBean Server connection... duh.
+
+  public int getPid() {
+    return vmPid;
+  }
+
+  public String getAddress() throws IOException {
+    return ConnectorAddressLink.importFrom(vmPid);
+  }
+
+  public String getJavaOptions() {
+    return javaOptions;
+  }
+
+  public void setJavaOptions(String javaOptions) {
+    this.javaOptions = javaOptions;
+  }
+
+  public String getStartClass() {
+    return startClass;
+  }
+
+  public void setStartClass(String startClass) {
+    this.startClass = startClass;
+  }
+
+  public int getVmPid() {
+    return vmPid;
+  }
+
+  public void setVmPid(int vmPid) {
+    this.vmPid = vmPid;
+  }
+
+  public String getVmName() {
+
+    this.buildVmName();
+    return vmName;
+  }
+
+  public void setVmName(String vmName) {
+    this.vmName = vmName;
+  }
+
+  public String commandLine() {
+    return startClass;
+  }
+
+  public MBeanServerConnection getMbsc() {
+    if (mbsc == null)
+      try {
+        mbsc = this.connect();
+      } catch (IOException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    return mbsc;
+  }
+
+  public void setMbsc(MBeanServerConnection mbsc) {
+    this.mbsc = mbsc;
+  }
+
+  private MBeanServerConnection connect() throws IOException {
+    //Create the JMXCconnectorServer
+    JMXConnector cntor = JMXConnectorFactory.newJMXConnector(new JMXServiceURL(this.getAddress()), null);
+    //      The connection environment map, null in this case
+    //      May contain - for example - user's credentials
+    //      Connect
+    cntor.connect(null);
+    //      Obtain a "stub" for the remote MBeanServer
+    return cntor.getMBeanServerConnection();
+  }
+
+  protected void initFromProcessId(int pid) {
+    String jmxurl = null;
+    MonitoredHost monitoredhost = null;
+    try {
+      monitoredhost = MonitoredHost.getMonitoredHost(new HostIdentifier((String) null));
+    } catch (MonitorException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (URISyntaxException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    try {
+      jmxurl = ConnectorAddressLink.importFrom(pid);
+    } catch (InstrumentationException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Older JVM running");
+      }
+      //Older than 1.5 JDK , ignore this exception
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    if (jmxurl != null)
+      try {
+        VmIdentifier vmidentifier = new VmIdentifier(Integer.toString(pid));
+        String clarg = MonitoredVmUtil.commandLine(monitoredhost.getMonitoredVm(vmidentifier));
+        String args = MonitoredVmUtil.jvmArgs(monitoredhost.getMonitoredVm(vmidentifier));
+        this.setVmPid(pid);
+        this.setStartClass(clarg);
+        this.setJavaOptions(args);
+      } catch (MonitorException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      } catch (URISyntaxException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    buildVmName();
+  }
+
+  protected abstract void buildVmName();
+//    //Obtain -Dtmc.vm.name variable, if not obtain service name from Tomcat
+//    String[] argarray = javaOptions.split(" ");
+//    for (String string : argarray) {
+//      //System.out.println(string);
+//      if (string.startsWith("-Dtmc.vm.name")) {
+//        String[] temp = string.split("=");
+//        this.vmName = temp[1];
+//      }
+//    }
+//  }
+
+  public CompositeDataSupport getHeapInfo() throws AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IOException, MalformedObjectNameException {
+    CompositeDataSupport ret = null;
+    if (this.getMbsc() != null) {
+      ret = (CompositeDataSupport) this.getMbsc().getAttribute(new ObjectName("java.lang:type=Memory"), "HeapMemoryUsage");
+    }
+    return ret;
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/jmx/TMCJMXClient.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/jmx/TMCJMXClient.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/jmx/TMCJMXClient.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/jmx/TMCJMXClient.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,179 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.jmx;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TMCJMXClient.java,v 1.1 2006/03/02 19:19:41 drtobes Exp $
+ * @deprecated
+ */
+public class TMCJMXClient {
+
+  public static ObjectName memObj;
+
+  public TMCJMXClient() {
+    try {
+      memObj = new ObjectName("java.lang:type=Memory");
+    } catch (MalformedObjectNameException e) {
+      e.printStackTrace();
+    } catch (NullPointerException e) {
+      e.printStackTrace();
+    }
+  }
+
+  public static String checkContext(String context) {
+    if (context.startsWith("/")) {
+      return context.substring(1);
+    } else
+      return context;
+
+  }
+
+//  public static void main(String[] args) {
+//    TMCJMXClient tjc = new TMCJMXClient();
+//    JMXThread jt = new JMXThread("Agent");
+//    jt.start();
+//    System.out.println("Hey");
+//    boolean mainloop = true;
+//    boolean tomcatloop = true;
+//    boolean vmloop = true;
+//    InputStreamReader is = new InputStreamReader(System.in);
+//    BufferedReader stdin = new BufferedReader(is);
+//    String test;
+//    while (mainloop) {
+//      System.out.println("Enter one of the following commands?");
+//      System.out.println("viewAll| tomcat| vm| exit");
+//
+//      try {
+//        test = stdin.readLine();
+//        //System.out.println(test);
+//        if (test.equalsIgnoreCase("viewAll")) {
+//          jt.viewCache();
+//        }
+//        if (test.equalsIgnoreCase("tomcat")) {
+//          tomcatloop = true;
+//          System.out.println("Choose of the Tomcats from below, enter Tomcat Name?");
+//          jt.viewTomcatCache();
+//          String tcname = stdin.readLine();
+//          JMXTomcat jmt = new JMXTomcat(jt.getVmCache().get(tcname));
+//          jmt.getAllContexts();
+//          while (tomcatloop) {
+//            System.out.println("Tomcat Menu: [viewContexts|start|stop|reload|sessions|exit]");
+//            String tString = stdin.readLine().trim();
+//            if (tString.toLowerCase().startsWith("viewcontexts")) {
+//              //System.out.println("Contexts");
+//
+//              System.out.println(jmt.printContexts());
+//            }
+//            if (tString.toLowerCase().startsWith("start")) {
+//              System.out.println("Type name of context to Start");
+//              System.out.println(jmt.printContexts());
+//              String ctx = stdin.readLine();
+//              System.out.println(jmt.startContext(checkContext(ctx)));
+//            }
+//            if (tString.toLowerCase().startsWith("stop")) {
+//              System.out.println("Type name of contex to Stop");
+//              System.out.println(jmt.printContexts());
+//              String ctx = stdin.readLine();
+//              System.out.println(jmt.stopContext(checkContext(ctx)));
+//            }
+//            if (tString.toLowerCase().startsWith("reload")) {
+//              System.out.println("Type name of contex to reload");
+//              System.out.println(jmt.printContexts());
+//              String ctx = stdin.readLine();
+//              System.out.println(jmt.reloadContext(checkContext(ctx)));
+//            }
+//            if (tString.toLowerCase().startsWith("sessions")) {
+//              System.out.println("Type name of contex to retrieve sessions for");
+//              System.out.println(jmt.printContexts());
+//              String ctx = stdin.readLine();
+//              System.out.println(jmt.getActiveSessions(checkContext(ctx)));
+//            }
+//
+//
+//            if (tString.trim().equalsIgnoreCase("exit")) {
+//              tomcatloop = false;
+//            }
+//          }
+//        }
+//        if (test.equalsIgnoreCase("vm")) {
+//          System.out.println("Choose of the JVMs from below, Enter pid of java process?");
+//          jt.viewCache();
+//          String vmname = stdin.readLine();
+//          MBeanServerConnection mbsc = null;
+//          vmloop = true;
+//
+//          try {
+//            int pid = Integer.parseInt(vmname);
+//            mbsc = JMXTomcat.connect(pid);
+//
+//          } catch (NumberFormatException nfe) {
+//            //mbsc = JMXTomcat.connect(vmname);
+//          }
+//
+//          //JMXTomcat jmt = new JMXTomcat(jt.getVmCache().get(tcname));
+//          //jmt.getAllContexts();
+//          while (vmloop) {
+//            System.out.println("VM Menu: [viewHeap|exit]");
+//            String vString = stdin.readLine().trim();
+//            if (vString.trim().equalsIgnoreCase("viewHeap")) {
+//              //System.out.println("Contexts");
+//              JMXConnect.getHeapInfo(mbsc, memObj);
+//            }
+//
+//            if (vString.trim().equalsIgnoreCase("exit")) {
+//              vmloop = false;
+//            }
+//          }
+//        }
+//
+//
+//        if (test.equalsIgnoreCase("exit")) {
+//          mainloop = false;
+//          System.exit(1);
+//        }
+//
+//        //jt.viewCache();
+//
+//      } catch (IOException e) {
+//        e.printStackTrace();
+//      } catch (MalformedObjectNameException e) {
+//        e.printStackTrace();
+//      } catch (AttributeNotFoundException e) {
+//        e.printStackTrace();
+//      } catch (InstanceNotFoundException e) {
+//        e.printStackTrace();
+//      } catch (NullPointerException e) {
+//        e.printStackTrace();
+//      } catch (MBeanException e) {
+//        e.printStackTrace();
+//      } catch (ReflectionException e) {
+//        e.printStackTrace();
+//      }
+//    }
+//
+//
+//  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/job/CommandLineJob.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/job/CommandLineJob.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/job/CommandLineJob.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/job/CommandLineJob.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,28 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.job;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: CommandLineJob.java,v 1.1 2006/03/02 19:19:41 drtobes Exp $
+ */
+public class CommandLineJob {
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/job/MonitoringJob.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/job/MonitoringJob.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/job/MonitoringJob.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/job/MonitoringJob.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,62 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.job;
+
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+import lokahi.core.api.function.Function;
+import lokahi.core.common.util.PropertiesFile;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: MonitoringJob.java,v 1.2 2006/03/06 22:31:43 drtobes Exp $
+ */
+public class MonitoringJob extends AgentJob {
+
+  public MonitoringJob(String name, String parentName, String commandOptions, String returnTo, String returnEndpoint, String returnMethod) {
+    this.setName(name);
+    this.setParentName(parentName);
+    this.setReturnTo(returnTo);
+    this.setReturnEndpoint(returnEndpoint);
+    this.setReturnMethod(returnMethod);
+    String functionCommand;
+    String opts;
+    if (commandOptions.indexOf(PropertiesFile.getConstantValue("agent.delim.options")) == -1) {
+      functionCommand = commandOptions;
+      opts = "";
+    } else {
+      functionCommand = commandOptions.substring(0, commandOptions.indexOf(PropertiesFile.getConstantValue("agent.delim.options")));
+      opts = commandOptions.substring(commandOptions.indexOf(PropertiesFile.getConstantValue("agent.delim.options")));
+    }
+    this.setFunction(Function.getFunction(functionCommand));
+    this.setOptions(opts.split(PropertiesFile.getConstantValue("agent.delim.options")));
+  }
+
+  public MonitoringJob(String name, String parentName, String commandOptions, String returnTo, String returnEndpoint, String returnMethod, String attachment) {
+    this(name, parentName, commandOptions, returnTo, returnEndpoint, returnMethod);
+    this.setAttachment(attachment);
+  }
+
+  public TaskType getType() {
+    return TaskType.MONITOR;
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/job/ScheduledJob.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/job/ScheduledJob.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/job/ScheduledJob.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/job/ScheduledJob.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,61 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.job;
+
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+import lokahi.core.api.function.Function;
+import lokahi.core.common.util.PropertiesFile;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: ScheduledJob.java,v 1.2 2006/03/06 22:31:43 drtobes Exp $
+ */
+public class ScheduledJob extends AgentJob {
+
+  public ScheduledJob(String name, String parentName, String commandOptions, String returnTo, String returnEndpoint, String returnMethod) {
+    this.setName(name);
+    this.setParentName(parentName);
+    this.setReturnTo(returnTo);
+    this.setReturnEndpoint(returnEndpoint);
+    this.setReturnMethod(returnMethod);
+    String functionCommand;
+    String opts;
+    if (commandOptions.indexOf(PropertiesFile.getConstantValue("agent.delim.options")) == -1) {
+      functionCommand = commandOptions;
+      opts = "";
+    } else {
+      functionCommand = commandOptions.substring(0, commandOptions.indexOf(PropertiesFile.getConstantValue("agent.delim.options")));
+      opts = commandOptions.substring(commandOptions.indexOf(PropertiesFile.getConstantValue("agent.delim.options")));
+    }
+    this.setFunction(Function.getFunction(functionCommand));
+    this.setOptions(opts.split(PropertiesFile.getConstantValue("agent.delim.options")));
+  }
+
+  public ScheduledJob(String name, String parentName, String commandOptions, String returnTo, String returnEndpoint, String returnMethod, String attachment) {
+    this(name, parentName, commandOptions, returnTo, returnEndpoint, returnMethod);
+    this.setAttachment(attachment);
+  }
+
+  public TaskType getType() {
+    return TaskType.SCHEDULED_JOB;
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/runnable/JobScheduler.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/runnable/JobScheduler.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/runnable/JobScheduler.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/runnable/JobScheduler.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,87 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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.
+*/
+package lokahi.core.agent.runnable;
+
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.interfaces.AgentTask;
+import lokahi.core.agent.util.TaskFactory;
+import lokahi.core.api.state.State;
+import org.apache.log4j.Logger;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: JobScheduler.java,v 1.2 2006/03/06 22:31:44 drtobes Exp $
+ */
+public class JobScheduler implements Runnable {
+  static final Logger logger = Logger.getLogger(JobScheduler.class);
+  private static volatile boolean run = false;
+
+  public static boolean shouldRun() {
+    return run;
+  }
+
+  public static void setRun(boolean run) {
+    JobScheduler.run = run;
+  }
+
+  public JobScheduler() {
+    setRun(true);
+  }
+
+  public void run() {
+    while (shouldRun()) {
+      Collection<AgentJob> jobs = AgentJob.getJobs(State.NEW);
+      for (AgentJob j : jobs) {
+        AgentTask task = TaskFactory.getTask(j);
+        if (task != null) {
+          Runnable r = task.getRunnable();
+          if (r != null)
+            r.run();
+          if (task.isDone()) {
+            try {
+              j.setResult(task.getResult());
+              j.setStatus(State.COMPLETE);
+            } catch (Exception e) {
+              if (logger.isInfoEnabled()) {
+                logger.info("Exception: " + e.getMessage());
+              }
+              j.setResult(e.getMessage());
+              j.setStatus(State.FAILED);
+            }
+            try {
+              j.update();
+            } catch (SQLException e) {
+              if (logger.isInfoEnabled()) {
+                logger.info("Exception: " + e.getMessage());
+              }
+            }
+          }
+        }
+      }
+      try {
+        Thread.sleep(1000);
+      } catch (InterruptedException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+  }
+
+}
\ No newline at end of file



Mime
View raw message