Author: adietish
Date: 2011-07-18 11:59:37 -0400 (Mon, 18 Jul 2011)
New Revision: 33022
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/IPollResultListener.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/AbstractJBossBehaviourDelegate.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/PollThread.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/PollThreadUtils.java
Log:
[JBIDE-9359] deprecated #alertBehaviour, replaced by #alertListener. The ServerBehaviour
would now add a listener to the poller which then would get informed of the outcome of the
polling. The server behavior could then act upon (and not the PollThread like it was
before).
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/AbstractJBossBehaviourDelegate.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/AbstractJBossBehaviourDelegate.java 2011-07-18
14:56:59 UTC (rev 33021)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/AbstractJBossBehaviourDelegate.java 2011-07-18
15:59:37 UTC (rev 33022)
@@ -93,9 +93,29 @@
protected void pollServer(boolean expectedState, IServerStatePoller poller) {
stopPolling();
- this.pollThread = PollThreadUtils.pollServer(expectedState, poller, pollThread,
actualBehavior);
+ this.pollThread = PollThreadUtils.pollServer(expectedState, poller, pollThread,
onPollingFinished(),
+ getServer());
}
+ protected IPollResultListener onPollingFinished() {
+ return new IPollResultListener() {
+
+ @Override
+ public void stateNotAsserted(boolean expectedState, boolean currentState) {
+ stop(true);
+ }
+
+ @Override
+ public void stateAsserted(boolean expectedState, boolean currentState) {
+ if (currentState == IServerStatePoller.SERVER_UP) {
+ setServerStarted();
+ } else {
+ stop(true);
+ }
+ }
+ };
+ }
+
protected void stopPolling() {
cancelPolling(null);
}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/IPollResultListener.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/IPollResultListener.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/IPollResultListener.java 2011-07-18
15:59:37 UTC (rev 33022)
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.core.server.internal;
+
+public interface IPollResultListener {
+
+ /**
+ * Called if the poller did
+ * @param expectedState
+ * @param currentState
+ */
+ public void stateAsserted(boolean expectedState, boolean currentState);
+
+ public void stateNotAsserted(boolean expectedState, boolean currentState);
+}
Property changes on:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/IPollResultListener.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/PollThread.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/PollThread.java 2011-07-18
14:56:59 UTC (rev 33021)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/PollThread.java 2011-07-18
15:59:37 UTC (rev 33022)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.core.server.internal;
+import java.util.Date;
+
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
@@ -49,17 +51,31 @@
private boolean expectedState, abort, stateStartedOrStopped;
private IServerStatePoller poller;
private String abortMessage;
+ @Deprecated
private DelegatingServerBehavior behavior;
private String pollerId;
+ private IPollResultListener listener;
+ private IServer server;
+ @Deprecated
public PollThread(boolean expectedState, IServerStatePoller poller,
DelegatingServerBehavior behavior) {
super(getThreadName(behavior.getServer()));
this.expectedState = expectedState;
this.behavior = behavior;
+ this.server = behavior.getServer();
this.poller = poller;
this.abort = false;
}
+ public PollThread(boolean expectedState, IServerStatePoller poller, IPollResultListener
listener, IServer server) {
+ super(getThreadName(server));
+ this.expectedState = expectedState;
+ this.poller = poller;
+ this.server = server;
+ this.listener = listener;
+ this.abort = false;
+ }
+
private static String getThreadName(IServer server) {
return NLS.bind(Messages.ServerPollerThreadName, server.getName());
}
@@ -86,7 +102,8 @@
if (poller == null) {
alertEventLogStarting();
alertPollerNotFound();
- alertBehavior(!expectedState);
+// alertBehavior(!expectedState);
+ alertListener(!expectedState);
return;
}
@@ -115,7 +132,8 @@
poller.cancel(IServerStatePoller.CANCEL);
poller.cleanup();
alertEventLogPollerException(e);
- alertBehavior(!expectedState);
+// alertBehavior(!expectedState);
+ alertListener(!expectedState);
return;
} catch (RequiresInfoException rie) {
// This way each request for new info is checked only once.
@@ -138,7 +156,7 @@
// we stopped. Did we abort?
if (stateStartedOrStopped) {
- int state = behavior.getServer().getServerState();
+ int state = server.getServerState();
boolean success = false;
if (expectedState == IServerStatePoller.SERVER_UP)
success = state == IServer.STATE_STARTED;
@@ -159,7 +177,8 @@
try {
currentState = poller.getState();
poller.cleanup();
- alertBehavior(currentState);
+// alertBehavior(currentState);
+ alertListener(currentState);
if (finalAlert) {
alertEventLog(currentState);
}
@@ -168,7 +187,8 @@
poller.cancel(IServerStatePoller.CANCEL);
poller.cleanup();
alertEventLogPollerException(pe);
- alertBehavior(!expectedState);
+// alertBehavior(!expectedState);
+ alertListener(!expectedState);
return;
} catch (RequiresInfoException rie) {
// You don't have an answer... liar!
@@ -187,7 +207,8 @@
// we're up (failed to shutdown)
// all other cases, we're down.
currentState = (expectedState == (behavior ==
IServerStatePoller.TIMEOUT_BEHAVIOR_SUCCEED));
- alertBehavior(currentState);
+// alertBehavior(currentState);
+ alertListener(currentState);
}
}
}
@@ -198,7 +219,7 @@
}
protected boolean checkServerState() {
- int state = behavior.getServer().getServerState();
+ int state = server.getServerState();
if (state == IServer.STATE_STARTED)
return true;
if (state == IServer.STATE_STOPPED)
@@ -214,6 +235,7 @@
}
}
+ @Deprecated
protected void alertBehavior(boolean currentState) {
if (currentState != expectedState) {
// it didnt work... cancel all processes! force stop
@@ -226,8 +248,16 @@
}
}
+ protected void alertListener(boolean currentState) {
+ if (currentState != expectedState) {
+ listener.stateNotAsserted(currentState, expectedState);
+ } else {
+ listener.stateAsserted(currentState, expectedState);
+ }
+ }
+
protected IServer getServer() {
- return behavior.getServer();
+ return server;
}
/*
@@ -240,26 +270,26 @@
IStatus status = new Status(IStatus.INFO,
JBossServerCorePlugin.PLUGIN_ID, POLLING_ROOT_CODE | state, message, null);
- ServerLogger.getDefault().log(behavior.getServer(), status);
+ ServerLogger.getDefault().log(server, status);
}
protected void alertEventLogPollerException(PollingException e) {
IStatus status = new Status(IStatus.ERROR,
JBossServerCorePlugin.PLUGIN_ID, POLLING_FAIL_CODE, Messages.PollerFailure, e);
- ServerLogger.getDefault().log(behavior.getServer(), status);
+ ServerLogger.getDefault().log(server, status);
}
protected void alertEventLogAbort() {
IStatus status = new Status(IStatus.WARNING,
JBossServerCorePlugin.PLUGIN_ID, POLLING_FAIL_CODE | getStateMask(expectedState,
false),
NLS.bind(Messages.PollerAborted, abortMessage), null);
- ServerLogger.getDefault().log(behavior.getServer(), status);
+ ServerLogger.getDefault().log(server, status);
}
protected void alertEventLogTimeout() {
IStatus status = new Status(IStatus.ERROR,
JBossServerCorePlugin.PLUGIN_ID, POLLING_FAIL_CODE | getStateMask(expectedState,
false), "", null); //$NON-NLS-1$
- ServerLogger.getDefault().log(behavior.getServer(), status);
+ ServerLogger.getDefault().log(server, status);
}
protected void alertEventLogFailure() {
@@ -268,7 +298,7 @@
IStatus status = new Status(IStatus.ERROR,
JBossServerCorePlugin.PLUGIN_ID, POLLING_FAIL_CODE | getStateMask(expectedState,
false),
expectedState ? startupFailed : shutdownFailed, null);
- ServerLogger.getDefault().log(behavior.getServer(), status);
+ ServerLogger.getDefault().log(server, status);
}
protected void alertEventLogSuccess(boolean currentState) {
@@ -278,7 +308,7 @@
IStatus status = new Status(IStatus.INFO,
JBossServerCorePlugin.PLUGIN_ID, POLLING_ROOT_CODE | state | SUCCESS,
expectedState ? startupSuccess : shutdownSuccess, null);
- ServerLogger.getDefault().log(behavior.getServer(), status);
+ ServerLogger.getDefault().log(server, status);
}
protected void alertPollerNotFound() {
@@ -287,7 +317,7 @@
IStatus status = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
POLLING_FAIL_CODE | getStateMask(expectedState, false),
expectedState ? startupPollerNotFound : shutdownPollerNotFound, null);
- ServerLogger.getDefault().log(behavior.getServer(), status);
+ ServerLogger.getDefault().log(server, status);
}
protected int getStateMask(boolean expected, boolean success) {
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/PollThreadUtils.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/PollThreadUtils.java 2011-07-18
14:56:59 UTC (rev 33021)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/PollThreadUtils.java 2011-07-18
15:59:37 UTC (rev 33022)
@@ -13,8 +13,9 @@
import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.as.core.ExtensionManager;
import org.jboss.ide.eclipse.as.core.server.IServerStatePoller;
+import org.jboss.ide.eclipse.as.core.server.internal.DelegatingServerBehavior;
+import org.jboss.ide.eclipse.as.core.server.internal.IPollResultListener;
import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
-import org.jboss.ide.eclipse.as.core.server.internal.DelegatingServerBehavior;
import org.jboss.ide.eclipse.as.core.server.internal.PollThread;
import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
import org.jboss.ide.eclipse.as.core.server.internal.ServerStatePollerType;
@@ -121,6 +122,7 @@
* @return
* @return the new poll thread
*/
+ @Deprecated
public static PollThread pollServer(final boolean expectedState, PollThread
currentPollThread, DelegatingServerBehavior behaviour) {
IServerStatePoller poller = PollThreadUtils.getPoller(expectedState,
behaviour.getServer());
return pollServer(expectedState, poller, currentPollThread, behaviour);
@@ -136,6 +138,7 @@
* @param behaviour the server behavior to use.
* @return the new poll thread
*/
+ @Deprecated
public static PollThread pollServer(boolean expectedState, IServerStatePoller poller,
PollThread currentPollThread,
DelegatingServerBehavior behaviour) {
stopPolling(currentPollThread);
@@ -144,4 +147,22 @@
return newPollThread;
}
+ /**
+ * Stops the given poll thread and creates a new poll thread for the given
+ * expected state, poller, result listener and server.
+ *
+ * @param expectedState the state to wait for
+ * @param poller the poller to use to wait for the expected state
+ * @param pollThread the poll thread to stop
+ * @param listener the listener to inform about the polling result
+ * @return the new poll thread
+ */
+ public static PollThread pollServer(boolean expectedState, IServerStatePoller poller,
PollThread currentPollThread,
+ IPollResultListener listener, IServer server) {
+ stopPolling(currentPollThread);
+ PollThread newPollThread = new PollThread(expectedState, poller, listener, server);
+ newPollThread.start();
+ return newPollThread;
+ }
+
}