Permalink
Browse files

Fixed issues with refresh operation.

  • Loading branch information...
1 parent 8e2360b commit 4608109ab3b2689cf040fc6b9967c0a4cc8afc56 nierajsingh committed Feb 21, 2014
@@ -15,6 +15,7 @@
/*
* Errors
*/
+
public static final String ERROR_PERFORMING_CLOUD_FOUNDRY_OPERATION = "Error performing Cloud Foundry operation: {0}";
public static final String ERROR_WRONG_EMAIL_OR_PASSWORD = "Wrong email or password";
@@ -37,6 +38,18 @@
public static final String ERROR_FAILED_CLIENT_CREATION_NO_SPACE = "Unable to resolve locally stored organisation and space for the server instance {0}. The server instance may have to be cloned or created again.";
+ public static final String ERROR_FAILED_MODULE_REFRESH = "Failed to refresh list of applications. Application list may not be accurate. Check connection and try a manual refresh - Reason: {0}";
+
+ public static final String ERROR_FIRE_REFRESH = "Internal Error: Failed to resolve Cloud Foundry server from WST IServer. Manual server disconnect and reconnect may be required - Reason: {0}";
+
+ public static final String ERROR_INITIALISE_REFRESH_NO_SERVER = "Failed to initialise Cloud Foundry refresh job. Unable to resolve a Cloud Foundry server - {0}";
+
+ public static final String ERROR_APP_DEPLOYMENT_VALIDATION_ERROR = "Invalid application deployment information for: {0} - Unable to deploy or start application - {1}";
+
+ public static final String ERROR_NO_WST_MODULE = "Internal Error: No WST IModule specified - Unable to deploy or start application";
+
+ public static final String ERROR_NO_MAPPED_CLOUD_MODULE = "Internal Error: No mapped Cloud Foundry application module found for: {0} - Unable to deploy or start application";
+
/*
* Warnings
*/
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Pivotal Software, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Pivotal Software, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.cloudfoundry.ide.eclipse.internal.server.core;
+
+import org.cloudfoundry.ide.eclipse.internal.server.core.client.CloudOperationsConstants;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.wst.server.core.IServer;
+
+/**
+ * Handles refresh operations across the Cloud Foundry Eclipse plugin, including
+ * stopping and starting ongoing refresh operations, as well as notifying
+ * listeners on a refresh event.
+ *
+ */
+public class RefreshHandler {
+
+ protected long interval = -1;
+
+ /**
+ *
+ */
+
+ private BehaviourRefreshJob refreshJob;
+
+ private final CloudFoundryServer cloudServer;
+
+ public RefreshHandler(CloudFoundryServer cloudServer) {
+ this.cloudServer = cloudServer;
+ this.refreshJob = new BehaviourRefreshJob();
+ }
+
+ /**
+ * Stop a refresh operation at the next opportunity. There is no guarantee
+ * that the operation may stop immediately.
+ */
+ public synchronized void stop() {
+ doStart(-1);
+ }
+
+ /**
+ * Start refresh operation after the given interval.
+ * @param interval if interval > 0 operation will start. If interval <= -1,
+ * operation will stop at next available opportunity.
+ */
+ public synchronized void start(long interval) {
+ doStart(interval);
+ }
+
+ /**
+ * Starts a refresh operation. Implementing classes can specify a default
+ * interval time before the operation begins.
+ */
+ public synchronized void start() {
+ interval = CloudOperationsConstants.DEFAULT_INTERVAL;
+ doStart(interval);
+ }
+
+ protected void doStart(long interval) {
+ if (interval > -1) {
+ refreshJob.schedule(interval);
+ }
+ }
+
+ /**
+ * Notifies that a refresh has occurred. Implementing classes can determine
+ * the shape of the notification (i.e., if it fires a particular event
+ * defined by the implementing class, or another type), as well as how the
+ * firing takes places (e.g. whether a list of listeners in the implementing
+ * class are notified).
+ * @param monitor progress monitor. If invoked by the Cloud Foundry
+ * framework this should never be null.
+ */
+ public synchronized void fireRefreshEvent(IProgressMonitor monitor) {
+ // Do not create a Job for this, as this may be invoked many times, to
+ // avoid many Jobs being scheduled.
+ ServerEventHandler.getDefault().fireServerRefreshed(cloudServer);
+ }
+
+ protected void refreshFromJob(IProgressMonitor monitor) {
+ if (shouldRefresh()) {
+ fireRefreshEvent(monitor);
+ }
+ }
+
+ protected synchronized boolean shouldRefresh() {
+ return interval > -1;
+ }
+
+ /**
+ * Standard Behaviour refresh job, which refreshes the application modules
+ * through Behaviour API.
+ *
+ */
+ class BehaviourRefreshJob extends Job {
+
+ public BehaviourRefreshJob() {
+ super("Refresh Server Job");
+ setSystem(true);
+ }
+
+ @Override
+ public IStatus run(IProgressMonitor monitor) {
+
+ if (RefreshHandler.this.cloudServer.getServer().getServerState() == IServer.STATE_STARTED) {
+ RefreshHandler.this.refreshFromJob(monitor);
+ if (interval > 0) {
+ schedule(interval);
+ }
+ }
+
+ return Status.OK_STATUS;
+
+ }
+
+ }
+
+}
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Pivotal Software, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Pivotal Software, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.cloudfoundry.ide.eclipse.internal.server.core.client;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * Operations for deploying applications. Performs refresh operations common to
+ * deploying apps.
+ */
+public abstract class AbstractDeploymentOperation implements ICloudFoundryOperation {
+
+ protected final CloudFoundryServerBehaviour behaviour;
+
+ public AbstractDeploymentOperation(CloudFoundryServerBehaviour behaviour) {
+ this.behaviour = behaviour;
+ }
+
+ public void run(IProgressMonitor monitor) throws CoreException {
+ // Deployment operations may be long running so stop refresh
+ // until operation completes
+ behaviour.getRefreshHandler().stop();
+ try {
+ performOperation(monitor);
+ }
+ finally {
+ // For application operations, always refresh modules and fire event
+ // even
+ // if an exception is thrown. It may, for example, allow listeners
+ // to update the UI in case an app failed to deploy
+ behaviour.refreshModules(monitor);
+ behaviour.getRefreshHandler().fireRefreshEvent(monitor);
+ }
+ }
+
+ protected abstract void performOperation(IProgressMonitor monitor) throws CoreException;
+
+}
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 Pivotal Software, Inc.
+ * Copyright (c) 2013, 2014 Pivotal Software, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -20,17 +20,28 @@
*/
public abstract class BehaviourOperation implements ICloudFoundryOperation {
- private final CloudFoundryServerBehaviour behaviour;
+ protected final CloudFoundryServerBehaviour behaviour;
public BehaviourOperation(CloudFoundryServerBehaviour behaviour) {
this.behaviour = behaviour;
}
public void run(IProgressMonitor monitor) throws CoreException {
- behaviour.stopRefreshModules();
performOperation(monitor);
- // Only trigger a refresh IF the operation succeeded.
- behaviour.refreshModules(monitor);
+ // Only trigger a refresh IF the operation succeeded.
+ refresh(monitor);
+ }
+
+
+
+ /**
+ * Gets invoked after the operation completes. Does not get called if an
+ * operation failed.
+ * @param monitor
+ * @throws CoreException
+ */
+ protected void refresh(IProgressMonitor monitor) throws CoreException {
+ behaviour.getRefreshHandler().fireRefreshEvent(monitor);
}
protected abstract void performOperation(IProgressMonitor monitor) throws CoreException;
Oops, something went wrong.

0 comments on commit 4608109

Please sign in to comment.