use of com.datatorrent.bufferserver.internal.FastDataList in project apex-core by apache.
the class Server method handleSubscriberRequest.
/**
*
* @param request
* @param key
*/
private void handleSubscriberRequest(final SubscribeRequestTuple request, final SelectionKey key) {
try {
serverHelperExecutor.submit(new Runnable() {
@Override
public void run() {
final String upstream_identifier = request.getUpstreamIdentifier();
/*
* if there is already a datalist registered for the type in which this client is interested,
* then get a iterator on the data items of that data list. If the datalist is not registered,
* then create one and register it. Hopefully this one would be used by future upstream nodes.
*/
DataList dl = publisherBuffers.get(upstream_identifier);
if (dl == null) {
dl = Tuple.FAST_VERSION.equals(request.getVersion()) ? new FastDataList(upstream_identifier, blockSize, numberOfCacheBlocks, BACK_PRESSURE_ENABLED) : new DataList(upstream_identifier, blockSize, numberOfCacheBlocks, BACK_PRESSURE_ENABLED);
DataList odl = publisherBuffers.putIfAbsent(upstream_identifier, dl);
if (odl != null) {
dl = odl;
}
}
final String identifier = request.getIdentifier();
final String type = request.getStreamType();
final long skipWindowId = (long) request.getBaseSeconds() << 32 | request.getWindowId();
final LogicalNode ln = new LogicalNode(identifier, upstream_identifier, type, dl.newIterator(skipWindowId), skipWindowId, eventloop);
int mask = request.getMask();
if (mask != 0) {
for (Integer bs : request.getPartitions()) {
ln.addPartition(bs, mask);
}
}
final LogicalNode oln = subscriberGroups.put(type, ln);
if (oln != null) {
oln.boot();
}
final Subscriber subscriber = new Subscriber(ln, request.getBufferSize());
eventloop.submit(new Runnable() {
@Override
public void run() {
key.attach(subscriber);
subscriber.registered(key);
subscriber.connected();
}
});
}
});
} catch (RejectedExecutionException e) {
logger.error("Received subscriber request {} after server {} termination. Disconnecting {}.", request, this, key.channel(), e);
if (key.isValid()) {
try {
key.channel().close();
} catch (IOException ioe) {
logger.error("Failed to close channel {}", key.channel(), ioe);
}
}
}
}
use of com.datatorrent.bufferserver.internal.FastDataList in project apex-core by apache.
the class Server method handlePublisherRequest.
/**
*
* @param request
* @param connection
* @return
*/
public DataList handlePublisherRequest(PublishRequestTuple request, AbstractLengthPrependerClient connection) {
String identifier = request.getIdentifier();
DataList dl = publisherBuffers.get(identifier);
if (dl != null) {
/*
* close previous connection with the same identifier which is guaranteed to be unique.
*/
AbstractLengthPrependerClient previous = publisherChannels.put(identifier, connection);
if (previous != null) {
eventloop.disconnect(previous);
}
try {
dl.rewind(request.getBaseSeconds(), request.getWindowId());
} catch (IOException ie) {
throw new RuntimeException(ie);
}
} else {
dl = Tuple.FAST_VERSION.equals(request.getVersion()) ? new FastDataList(identifier, blockSize, numberOfCacheBlocks, BACK_PRESSURE_ENABLED) : new DataList(identifier, blockSize, numberOfCacheBlocks, BACK_PRESSURE_ENABLED);
DataList odl = publisherBuffers.putIfAbsent(identifier, dl);
if (odl != null) {
dl = odl;
}
}
dl.setSecondaryStorage(storage, storageHelperExecutor);
return dl;
}
Aggregations