Skip to content

Commit

Permalink
new Plant class
Browse files Browse the repository at this point in the history
  • Loading branch information
laforge49 committed Oct 11, 2013
1 parent 6475106 commit af4199b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class Facility extends BladeBase implements AutoCloseable {

public final static String NAME_PROPERTY = "name";

public final static String PLANT_NAME = "Plant";

public final static String DEPENDENCY_PROPERTY_PREFIX = "dependency_";

/**
Expand Down Expand Up @@ -295,7 +297,7 @@ protected Object processSyncRequest() throws Exception {
};
}

private void firstSet(final String _propertyName,
protected void firstSet(final String _propertyName,
final Object _propertyValue) {
if (_propertyValue == null)
throw new IllegalArgumentException("value may not be null");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.agilewiki.jactor2.core.facilities;

import org.agilewiki.jactor2.core.messages.AsyncRequest;
import org.agilewiki.jactor2.core.messages.AsyncResponseProcessor;
import org.agilewiki.jactor2.core.messages.EventBus;
import org.agilewiki.jactor2.core.reactors.Inbox;
import org.agilewiki.jactor2.core.reactors.Outbox;

import java.util.concurrent.ThreadFactory;

public class Plant extends Facility {

/**
* Create a Plant.
*/
public Plant() throws Exception {
this(
Inbox.DEFAULT_INITIAL_LOCAL_QUEUE_SIZE,
Outbox.DEFAULT_INITIAL_BUFFER_SIZE,
20,
new DefaultThreadFactory());
}

/**
* Create a Plant.
*
* @param _threadCount The thread pool size.
*/
public Plant(final int _threadCount) throws Exception {
this(
Inbox.DEFAULT_INITIAL_LOCAL_QUEUE_SIZE,
Outbox.DEFAULT_INITIAL_BUFFER_SIZE,
_threadCount,
new DefaultThreadFactory());
}

/**
* Create a Plant.
*
* @param _initialLocalMessageQueueSize How big should the initial inbox doLocal queue size be?
* @param _initialBufferSize How big should the initial outbox (per target Reactor) buffer size be?
* @param _threadCount The thread pool size.
* @param _threadFactory The factory used to create threads for the threadpool.
*/
public Plant(final int _initialLocalMessageQueueSize,
final int _initialBufferSize,
final int _threadCount,
final ThreadFactory _threadFactory) throws Exception {
super(_initialLocalMessageQueueSize, _initialBufferSize, _threadCount, _threadFactory);
firstSet(NAME_PROPERTY, PLANT_NAME);
}

public AsyncRequest<Void> dependencyAReq(final Facility _dependency) {
return new AsyncBladeRequest<Void>() {
@Override
protected void processAsyncRequest() throws Exception {
throw new UnsupportedOperationException("Plant can have no dependencies");
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ public class ServiceTest extends TestCase {
Reactor testReactor;

public void test() throws Exception {
Facility testFacility = new Facility();
testFacility.setNameSReq("Plant").call();
Plant plant = new Plant();
Facility clientFacility = new Facility();
clientFacility.setNameSReq("client").call();
clientFacility.dependencyAReq(testFacility).call();
clientFacility.dependencyAReq(plant).call();
final Facility serverFacility = new Facility();
serverFacility.setNameSReq("server").call();
serverFacility.dependencyAReq(testFacility).call();
serverFacility.dependencyAReq(plant).call();
try {
testReactor = new NonBlockingReactor(testFacility);
testReactor = new NonBlockingReactor(plant);
Server server = new Server(new NonBlockingReactor(serverFacility));
final Client client = new Client(new NonBlockingReactor(clientFacility), server);
new AsyncBladeRequest<Void>() {
Expand All @@ -41,7 +40,7 @@ public void processAsyncResponse(Boolean response) throws Exception {
}
}.call();
} finally {
testFacility.close();
plant.close();
}
}

Expand Down

0 comments on commit af4199b

Please sign in to comment.