[jboss-cvs] jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/internal ...
Robert Stryker
rawblem at gmail.com
Thu Nov 9 19:26:26 EST 2006
User: rawb
Date: 06/11/09 19:26:26
Added: as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/internal
TimeoutPoller.java TwiddlePoller.java
Log:
Rewrote Core entirley. It's clean and spiffy now.
Revision Changes Path
1.1 date: 2006/11/10 00:26:25; author: rawb; state: Exp;jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/internal/TimeoutPoller.java
Index: TimeoutPoller.java
===================================================================
/**
* JBoss, a Division of Red Hat
* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.ide.eclipse.as.core.runtime.server.internal;
import java.util.Date;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.IServerAttributes;
import org.jboss.ide.eclipse.as.core.model.ServerProcessModel;
import org.jboss.ide.eclipse.as.core.runtime.IServerStatePoller;
import org.jboss.ide.eclipse.as.core.server.JBossServer;
import org.jboss.ide.eclipse.as.core.server.attributes.IServerPollingAttributes;
// Wait 10 seconds, then say it's at it's expected state
public class TimeoutPoller implements IServerStatePoller {
private boolean expectedState;
private long endTime;
private IServer server;
int timeout = -1;
public void beginPolling(IServer server, boolean expectedState) {
this.server = server;
this.expectedState = expectedState;
this.endTime = new Date().getTime() + getTimeout();
}
protected int getTimeout() {
return 15000;
}
public void cancel(int type) {
}
public boolean getState() {
if( new Date().getTime() > endTime ) return expectedState;
return !expectedState;
}
public boolean isComplete() {
if( new Date().getTime() > endTime ) return true;
return false;
}
public void cleanup() {
if( !expectedState ) {
ServerProcessModel.getDefault().getModel(server.getId()).clearAll();
}
}
}
1.1 date: 2006/11/10 00:26:25; author: rawb; state: Exp;jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/internal/TwiddlePoller.java
Index: TwiddlePoller.java
===================================================================
/**
* JBoss, a Division of Red Hat
* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.ide.eclipse.as.core.runtime.server.internal;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.as.core.model.ServerProcessModel;
import org.jboss.ide.eclipse.as.core.model.ServerProcessModel.ServerProcessModelEntity;
import org.jboss.ide.eclipse.as.core.runtime.IServerStatePoller;
import org.jboss.ide.eclipse.as.core.server.JBossServer;
import org.jboss.ide.eclipse.as.core.server.JBossServerLaunchConfiguration;
import org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper;
import org.jboss.ide.eclipse.as.core.server.TwiddleLauncher;
import org.jboss.ide.eclipse.as.core.server.TwiddleLauncher.ProcessData;
import org.jboss.ide.eclipse.as.core.server.attributes.IServerPollingAttributes;
public class TwiddlePoller implements IServerStatePoller {
private boolean expectedState;
private int started;
private boolean canceled;
private boolean done;
private IServer server;
private PollerRunnable currentRunnable;
public void beginPolling(IServer server, boolean expectedState) {
this.expectedState = expectedState;
this.canceled = false;
this.done = false;
this.server = server;
launchTwiddlePoller();
}
private class PollerRunnable implements Runnable {
private TwiddleLauncher launcher;
public void run() {
String args = "get \"jboss.system:type=Server\" Started";
while( !canceled && !done ) {
// are start processes still going?
ServerProcessModelEntity ent = ServerProcessModel.getDefault().getModel(server.getId());
IProcess[] processes = ent.getProcesses(JBossServerLaunchConfiguration.START);
if( ServerProcessModel.allProcessesTerminated(processes)) {
done = true;
started = 0;
} else {
launcher = new TwiddleLauncher();
ProcessData[] datas = launcher.getTwiddleResults(server, args, true);
if( datas.length == 1 ) {
ProcessData d = datas[0];
String out = d.getOut();
if( out.startsWith("Started=true")) {
started = 1;
} else if(out.startsWith("Started=false")) {
started = -1; // it's alive and responding
} else {
started = 0; // It's fully down
}
if( started == 1 && expectedState == SERVER_UP ) {
done = true;
} else if( started == 0 && expectedState == SERVER_DOWN) {
done = true;
}
}
}
}
}
public void setCanceled() {
if( launcher != null ) {
launcher.setCanceled();
}
}
}
private void launchTwiddlePoller() {
PollerRunnable run = new PollerRunnable();
Thread t = new Thread(run, "Twiddle Poller");
t.start();
}
public void cancel(int type) {
canceled = true;
}
public void cleanup() {
ServerProcessModelEntity ent = ServerProcessModel.getDefault().getModel(server.getId());
if( expectedState == SERVER_UP) {
ent.terminateProcesses(JBossServerLaunchConfiguration.TWIDDLE);
} else {
ent.terminateProcesses(JBossServerLaunchConfiguration.TWIDDLE);
ent.terminateProcesses(JBossServerLaunchConfiguration.STOP);
}
}
public boolean getState() {
if( started == 0 ) return SERVER_DOWN;
if( started == 1 ) return SERVER_UP;
if( !done && !canceled )
return !expectedState; // Not there yet.
return expectedState; // done or canceled, doesnt matter
}
public boolean isComplete() {
return done;
}
}
More information about the jboss-cvs-commits
mailing list