Skip to content

Commit

Permalink
new Plant.createFacilitySReq
Browse files Browse the repository at this point in the history
  • Loading branch information
laforge49 committed Oct 11, 2013
1 parent af4199b commit f25d17a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class Facility extends BladeBase implements AutoCloseable {
* A hash set of AutoCloseable objects.
* Can only be accessed via a request to the facility.
*/
private final Set<AutoCloseable> closeables = Collections
protected final Set<AutoCloseable> closeables = Collections
.newSetFromMap(new WeakHashMap<AutoCloseable, Boolean>());

/**
Expand Down Expand Up @@ -132,6 +132,24 @@ public Facility(final int _initialLocalMessageQueueSize,
propertyChangeSubscribers = new EventBus<FacilityPropertyChangeSubscriber>(internalReactor);
}

/**
* Create a Facility.
*
* @param _name The name of the facility.
* @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.
*/
protected Facility(final String _name,
final int _initialLocalMessageQueueSize,
final int _initialBufferSize,
final int _threadCount,
final ThreadFactory _threadFactory) throws Exception {
this(_initialLocalMessageQueueSize, _initialBufferSize, _threadCount, _threadFactory);
firstSet(NAME_PROPERTY, _name);
}

/**
* Returns the logger to be used by targetReactor.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.messages.SyncRequest;
import org.agilewiki.jactor2.core.reactors.Inbox;
import org.agilewiki.jactor2.core.reactors.Outbox;

Expand Down Expand Up @@ -58,4 +59,57 @@ protected void processAsyncRequest() throws Exception {
}
};
}

public SyncRequest<Facility> createFacilitySReq(final String _name) throws Exception {
return new SyncBladeRequest<Facility>() {
@Override
protected Facility processSyncRequest() throws Exception {
Facility facility = new Facility(
_name,
Inbox.DEFAULT_INITIAL_LOCAL_QUEUE_SIZE,
Outbox.DEFAULT_INITIAL_BUFFER_SIZE,
20,
new DefaultThreadFactory());
closeables.add(facility);
return facility;
}
};
}

public SyncRequest<Facility> createFacilitySReq(final String _name,
final int _threadCount) throws Exception {
return new SyncBladeRequest<Facility>() {
@Override
protected Facility processSyncRequest() throws Exception {
Facility facility = new Facility(
_name,
Inbox.DEFAULT_INITIAL_LOCAL_QUEUE_SIZE,
Outbox.DEFAULT_INITIAL_BUFFER_SIZE,
_threadCount,
new DefaultThreadFactory());
closeables.add(facility);
return facility;
}
};
}

public SyncRequest<Facility> createFacilitySReq(final String _name,
final int _initialLocalMessageQueueSize,
final int _initialBufferSize,
final int _threadCount,
final ThreadFactory _threadFactory) throws Exception {
return new SyncBladeRequest<Facility>() {
@Override
protected Facility processSyncRequest() throws Exception {
Facility facility = new Facility(
_name,
_initialLocalMessageQueueSize,
_initialBufferSize,
_threadCount,
_threadFactory);
closeables.add(facility);
return facility;
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ public class ServiceTest extends TestCase {

public void test() throws Exception {
Plant plant = new Plant();
Facility clientFacility = new Facility();
clientFacility.setNameSReq("client").call();
clientFacility.dependencyAReq(plant).call();
final Facility serverFacility = new Facility();
serverFacility.setNameSReq("server").call();
serverFacility.dependencyAReq(plant).call();
Facility clientFacility = plant.createFacilitySReq("Client").call();
final Facility serverFacility = plant.createFacilitySReq("Server").call();
try {
testReactor = new NonBlockingReactor(plant);
Server server = new Server(new NonBlockingReactor(serverFacility));
Expand Down

0 comments on commit f25d17a

Please sign in to comment.