Skip to content

Commit

Permalink
and the continuation API is now minimal
Browse files Browse the repository at this point in the history
minimal for now! it may get smaller later!

there are some small polishings that will follow
  • Loading branch information
heinousjay committed Nov 27, 2014
1 parent 63f29a2 commit 2f72648
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 27 deletions.
10 changes: 5 additions & 5 deletions kernel/src/main/java/jj/document/ElementMessageProcessor.java
Expand Up @@ -22,7 +22,7 @@
import jj.http.server.websocket.CurrentWebSocketConnection;
import jj.http.server.websocket.WebSocketConnection;
import jj.jjmessage.JJMessage;
import jj.script.ContinuationCoordinator;
import jj.script.ContinuationResumer;
import jj.script.CurrentScriptEnvironment;

/**
Expand All @@ -34,26 +34,26 @@
@Singleton
class ElementMessageProcessor implements DocumentWebSocketMessageProcessor {

private final ContinuationCoordinator continuationCoordinator;
private final ContinuationResumer continuationResumer;

private final CurrentWebSocketConnection currentConnection;

private final CurrentScriptEnvironment env;

@Inject
ElementMessageProcessor(
final ContinuationCoordinator continuationCoordinator,
final ContinuationResumer continuationResumer,
final CurrentWebSocketConnection connection,
final CurrentScriptEnvironment env
) {
this.continuationCoordinator = continuationCoordinator;
this.continuationResumer = continuationResumer;
this.currentConnection = connection;
this.env = env;
}

@Override
public void handle(WebSocketConnection connection, JJMessage message) {
continuationCoordinator.resume(message.pendingKey(), new EventSelection(message.element().selector, currentConnection, env));
continuationResumer.resume(message.pendingKey(), new EventSelection(message.element().selector, currentConnection, env));
}

}
10 changes: 5 additions & 5 deletions kernel/src/main/java/jj/document/ResultMessageProcessor.java
Expand Up @@ -22,7 +22,7 @@

import jj.http.server.websocket.WebSocketConnection;
import jj.jjmessage.JJMessage;
import jj.script.ContinuationCoordinator;
import jj.script.ContinuationResumer;
import jj.script.ScriptJSON;

/**
Expand All @@ -34,20 +34,20 @@
@Singleton
class ResultMessageProcessor implements DocumentWebSocketMessageProcessor {

private final ContinuationCoordinator continuationCoordinator;
private final ContinuationResumer continuationResumer;

private final ScriptJSON json;

@Inject
ResultMessageProcessor(final ContinuationCoordinator continuationCoordinator, final ScriptJSON json) {
this.continuationCoordinator = continuationCoordinator;
ResultMessageProcessor(final ContinuationResumer continuationResumer, final ScriptJSON json) {
this.continuationResumer = continuationResumer;
this.json = json;
}

@Override
public void handle(WebSocketConnection connection, JJMessage message) {
Object value = message.result().value == null ? Undefined.instance : json.parse(message.result().value);
continuationCoordinator.resume(message.pendingKey(), value);
continuationResumer.resume(message.pendingKey(), value);
}

}
10 changes: 1 addition & 9 deletions kernel/src/main/java/jj/script/ContinuationCoordinator.java
Expand Up @@ -24,7 +24,7 @@
* @author jason
*
*/
public interface ContinuationCoordinator {
interface ContinuationCoordinator {

/**
* continuable String evaluation within the context of {@link ScriptEnvironment}
Expand Down Expand Up @@ -52,12 +52,4 @@ public interface ContinuationCoordinator {
* @return A key representing a pending continuation, or null if the execution completed
*/
ContinuationPendingKey resumeContinuation(ScriptEnvironment scriptEnvironment, ContinuationPendingKey pendingKey, Object result);

/**
* Resume a continuation, for use by code that constructs its own ContinuationPendingKey, such as from a network message
* @param pendingKey
* @param result
*/
void resume(ContinuationPendingKey pendingKey, Object result);

}
Expand Up @@ -21,7 +21,7 @@
*
*/
@Singleton
class ContinuationCoordinatorImpl implements ContinuationCoordinator {
class ContinuationCoordinatorImpl implements ContinuationCoordinator, ContinuationResumer {

private interface ContinuationExecution {
void run(RhinoContext context);
Expand Down
30 changes: 30 additions & 0 deletions kernel/src/main/java/jj/script/ContinuationResumer.java
@@ -0,0 +1,30 @@
/*
* Copyright 2012 Jason Miller
*
* 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 jj.script;

/**
* @author jason
*
*/
public interface ContinuationResumer {

/**
* Resume a continuation, for use by code that constructs its own ContinuationPendingKey, such as from a network message
* @param pendingKey
* @param result
*/
void resume(ContinuationPendingKey pendingKey, Object result);
}
2 changes: 2 additions & 0 deletions kernel/src/main/java/jj/script/ScriptModule.java
Expand Up @@ -19,6 +19,8 @@ protected void configure() {

bind(ContinuationCoordinator.class).to(ContinuationCoordinatorImpl.class);

bind(ContinuationResumer.class).to(ContinuationCoordinatorImpl.class);

bindExecutor(ScriptExecutorFactory.class);

install(new ScriptResourceModule());
Expand Down
Expand Up @@ -21,7 +21,7 @@
import jj.http.server.websocket.WebSocketConnection;
import jj.jjmessage.JJMessage;
import jj.jjmessage.MessageMaker;
import jj.script.ContinuationCoordinator;
import jj.script.ContinuationResumer;
import jj.script.ContinuationPendingKey;

import org.junit.Test;
Expand All @@ -37,7 +37,7 @@
@RunWith(MockitoJUnitRunner.class)
public class ElementMessageProcessorTest {

@Mock ContinuationCoordinator continuationCoordinator;
@Mock ContinuationResumer continuationResumer;

@Mock WebSocketConnection connection;

Expand All @@ -54,7 +54,7 @@ public void test() {
emp.handle(connection, jqm);

//then
verify(continuationCoordinator).resume(eq(jqm.pendingKey()), isA(EventSelection.class));
verify(continuationResumer).resume(eq(jqm.pendingKey()), isA(EventSelection.class));
}

}
Expand Up @@ -20,7 +20,7 @@
import jj.http.server.websocket.WebSocketConnection;
import jj.jjmessage.JJMessage;
import jj.jjmessage.MessageMaker;
import jj.script.ContinuationCoordinator;
import jj.script.ContinuationResumer;
import jj.script.ContinuationPendingKey;
import jj.script.ScriptJSON;

Expand All @@ -38,7 +38,7 @@
@RunWith(MockitoJUnitRunner.class)
public class ResultMessageProcessorTest {

@Mock ContinuationCoordinator continuationCoordinator;
@Mock ContinuationResumer continuationResumer;
@Mock ScriptJSON json;
@Mock WebSocketConnection connection;

Expand All @@ -52,7 +52,7 @@ public void testHandle() {
JJMessage message = MessageMaker.makeResult(id, value);
rmp.handle(connection, message);

verify(continuationCoordinator).resume(new ContinuationPendingKey(id), value);
verify(continuationResumer).resume(new ContinuationPendingKey(id), value);
}

@Test
Expand All @@ -63,7 +63,7 @@ public void testHandle2() {
JJMessage message = MessageMaker.makeResult(id, value);
rmp.handle(connection, message);

verify(continuationCoordinator).resume(new ContinuationPendingKey(id), Undefined.instance);
verify(continuationResumer).resume(new ContinuationPendingKey(id), Undefined.instance);
}

}

0 comments on commit 2f72648

Please sign in to comment.