Skip to content

Commit

Permalink
signalError implemented. Now it is possible to interrupt the context.
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankHossfeld committed Jan 27, 2016
1 parent 63f7c43 commit b4ddf86
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 114 deletions.
13 changes: 0 additions & 13 deletions .idea/libraries/Maven__org_gwt4e_sema4g_sema4g_1_1_0.xml

This file was deleted.

2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>sema4g-parent</artifactId>
<groupId>org.gwt4e.sema4g</groupId>
<version>1.2.3</version>
<version>1.3.0</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
20 changes: 12 additions & 8 deletions core/src/main/java/org/gwt4e/sema4g/client/SeMa4g.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import org.gwt4e.sema4g.client.commands.FinalCommand;
import org.gwt4e.sema4g.client.commands.InitCommand;
import org.gwt4e.sema4g.client.commands.SeMa4gCommand;
import org.gwt4e.sema4g.client.commands.SyncCommand;
import org.gwt4e.sema4g.client.commands.helper.SeMa4gCommand;
import org.gwt4e.sema4g.client.exceptions.SeMa4gException;

import com.google.gwt.core.client.GWT;
Expand Down Expand Up @@ -167,9 +167,10 @@ public void trigger() {
}

/**
* <p>This method will set the state to 'CANCELED' for all commands, that have not already started (state is 'WAITING').</p>
* This command can be called to interrupt the execution and
* start the error behavior.
*/
public void cancel() {
public void signalError() {
// set state
this.state = State.ERROR;
// cancel all not already started commands
Expand Down Expand Up @@ -264,16 +265,19 @@ private boolean hasNoDependency(SeMa4gCommand command) {
}

private void updateState() {
if (SeMa4gCommand.State.ERROR.equals(this.state)) {
return;
}

for (SeMa4gCommand seMa4gCommand : this.seMa4gCommands) {
if (seMa4gCommand.getState()
if (seMa4gCommand.getState().equals(SeMa4gCommand.State.ERROR)) {
this.state = State.ERROR;
return;
} else if (seMa4gCommand.getState()
.equals(SeMa4gCommand.State.WAITING) || seMa4gCommand.getState()
.equals(SeMa4gCommand.State.RUNNING)) {
this.state = State.RUNNING;
return;
} else if (seMa4gCommand.getState()
.equals(SeMa4gCommand.State.ERROR)) {
this.state = State.ERROR;
return;
}
}
this.state = State.FINISH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* the License.
*/

package org.gwt4e.sema4g.client.commands.helper;
package org.gwt4e.sema4g.client.commands;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -38,8 +38,6 @@ public abstract class AbstractCommand
/* dependencies */
private List<SeMa4gCommand> dependencies;

//------------------------------------------------------------------------------

protected AbstractCommand() {
// set state
this.state = State.WAITING;
Expand All @@ -49,8 +47,6 @@ protected AbstractCommand() {
id = SeMa4gUtils.getNextId();
}

//------------------------------------------------------------------------------

String getId() {
return id;
}
Expand Down Expand Up @@ -104,8 +100,6 @@ public void setState(State state) {
this.state = state;
}

//------------------------------------------------------------------------------

/**
* Definies the {@link SeMa4gCommand} (one or more) which have to
* be finished before this command can be executed.
Expand Down Expand Up @@ -178,7 +172,14 @@ public void startCheckCycleDependencies()
this.checkCycleDependencies(usedDependencies);
}

//------------------------------------------------------------------------------
/**
* This command can be called to interrupt the execution and
* start the error behavior.
*/
public void signalError() {
this.state = State.ERROR;
executionContext.signalError();
}

/**
* Use this method to implement the execution code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@

package org.gwt4e.sema4g.client.commands;

import org.gwt4e.sema4g.client.commands.helper.AbstractCommand;
import org.gwt4e.sema4g.client.commands.helper.SeMa4gCommand;

/**
* <p>A asynchronous command to use with SeMa4g.</p>
*/
Expand All @@ -45,17 +42,22 @@ public AsyncCommand() {
super();
}

public void onSuccess() {
public void setStateError() {
// update state
super.setState(State.FINISH);
// trigger execution context
super.getExecutionContext()
.trigger();
setState(State.ERROR);
}

@SuppressWarnings("unused")
public void onFailure(Throwable caught) {
public void setStateFinish() {
// update state
super.setState(SeMa4gCommand.State.ERROR);
setState(State.FINISH);
}

public void trigger() {
// trigger execution context
getExecutionContext().trigger();
}

public void failure(Throwable caught) {
signalError();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* the License.
*/

package org.gwt4e.sema4g.client.commands.helper;
package org.gwt4e.sema4g.client.commands;

import java.util.List;

import org.gwt4e.sema4g.client.SeMa4g;
import org.gwt4e.sema4g.client.exceptions.SeMa4gException;

import java.util.List;

/**
* This interface provide all needed methods to interact with the
* {@link SeMa4g}
Expand Down Expand Up @@ -85,6 +85,12 @@ SeMa4gCommand dependingOn(SeMa4gCommand... dependencies)
*/
void setState(State state);

/**
* This command can be called to interrupt the execution and
* start the error behavior.
*/
void signalError();

/**
* This method is used by the execution context to start the command
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

package org.gwt4e.sema4g.client.commands;

import org.gwt4e.sema4g.client.commands.helper.AbstractCommand;

/**
* <p>A synchronous command to use with SeMa4g.</p>
*/
Expand All @@ -51,6 +49,6 @@ public void run() {
// calll super run-method
super.run();
// update state
super.setState(State.FINISH);
setState(State.FINISH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,50 @@

package org.gwt4e.sema4g.client.commands.proxies;

import com.google.gwt.user.client.rpc.AsyncCallback;
import org.gwt4e.sema4g.client.commands.AsyncCommand;

import com.google.gwt.user.client.rpc.AsyncCallback;

/**
* <p>Add support for AsyncCallback in GWT {@link AsyncCallback}</p>
* <br /><br />
* <p>If you are using SeMa4g, you have to this AsyncCallbackProxy
* class instead of the AsyncCallback. Otherwise SeMa4g will not work.</p>
*/
public class AsyncCallbackProxy<C extends AsyncCallback<T>, T>
public abstract class AsyncCallbackProxy<T>
implements SeMa4gProxy,
AsyncCallback<T> {

private final C asyncCallback;
/* execution command of this proxy */
private AsyncCommand command;

//------------------------------------------------------------------------------

public AsyncCallbackProxy(AsyncCommand command,
C asyncCallback) {
public AsyncCallbackProxy(AsyncCommand command) {
super();
this.command = command;
this.asyncCallback = asyncCallback;
}

//------------------------------------------------------------------------------

@Override
public void onFailure(Throwable caught) {
// Set State
command.setStateError();
// do the default handling
asyncCallback.onFailure(caught);
onProxyFailure(caught);
// do the SeMa4g handling
command.onFailure(caught);
command.failure(caught);
}

@Override
public void onSuccess(T result) {
// Set State
command.setStateFinish();
// do the default handling
asyncCallback.onSuccess(result);
onProxySuccess(result);
// do the SeMa4g handling
command.onSuccess();
command.trigger();
}

protected abstract void onProxyFailure(Throwable caught);

protected abstract void onProxySuccess(T result);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,57 @@

package org.gwt4e.sema4g.client.commands.proxies;

import org.gwt4e.sema4g.client.commands.AsyncCommand;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
import org.gwt4e.sema4g.client.commands.AsyncCommand;

/**
* <p>Add support for RequestCallback in GWT {@link RequestCallback}</p>
* <br /><br />
* <p>If you are using SeMa4g, you have to this RequestCallbackProxy
* class instead of the RequestCallback. Otherwise SeMa4g will not work.</p>
*/
public class RequestCallbackProxy
public abstract class RequestCallbackProxy
implements SeMa4gProxy,
RequestCallback {

private final RequestCallback asyncCallback;
/* execution command of this proxy */
private AsyncCommand command;

//------------------------------------------------------------------------------

public RequestCallbackProxy(AsyncCommand command,
RequestCallback asyncCallback) {
public RequestCallbackProxy(AsyncCommand command) {
super();
this.command = command;
this.asyncCallback = asyncCallback;
}

//------------------------------------------------------------------------------

@Override
public void onResponseReceived(Request request,
Response response) {
// Set State
command.setStateFinish();
// do the default handling
asyncCallback.onResponseReceived(request,
onProxyResponseReceived(request,
response);
// do the SeMa4g handling
command.onSuccess();
command.trigger();
}

@Override
public void onError(Request request,
Throwable exception) {
// Set State
command.setStateError();
// do the default handling
asyncCallback.onError(request,
onProxyError(request,
exception);
// do the SeMa4g handling
command.onFailure(exception);
command.failure(exception);
}

protected abstract void onProxyError(Request request,
Throwable exception);

protected abstract void onProxyResponseReceived(Request request,
Response response);
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.gwt4e.sema4g</groupId>
<artifactId>sema4g-parent</artifactId>
<version>1.2.3</version>
<version>1.3.0</version>
<packaging>pom</packaging>
<name>sema4g (parent)</name>
<description>Managing asynchronous calls in GWT</description>
Expand Down
4 changes: 2 additions & 2 deletions resty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>sema4g-parent</artifactId>
<groupId>org.gwt4e.sema4g</groupId>
<version>1.2.3</version>
<version>1.3.0</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand All @@ -16,7 +16,7 @@

<properties>
<restyGWT.version>2.0.3</restyGWT.version>
<sema4g.version>1.1.0</sema4g.version>
<sema4g.version>1.3.0</sema4g.version>
</properties>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion resty/resty.iml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</content>
<orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.gwt4e.sema4g:sema4g:1.1.0" level="project" />
<orderEntry type="module" module-name="core" scope="PROVIDED" />
<orderEntry type="library" name="Maven: org.fusesource.restygwt:restygwt:2.0.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.google.gwt:gwt-servlet:2.7.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.gwt:gwt-user:2.7.0" level="project" />
Expand Down
Loading

0 comments on commit b4ddf86

Please sign in to comment.