use of com.datatorrent.bufferserver.internal.DataList in project apex-core by apache.
the class Server method handleResetRequest.
private void handleResetRequest(ResetRequestTuple request, final AbstractLengthPrependerClient ctx) throws IOException {
DataList dl;
dl = publisherBuffers.remove(request.getIdentifier());
byte[] message;
if (dl == null) {
message = ("Invalid identifier '" + request.getIdentifier() + "'").getBytes();
} else {
AbstractLengthPrependerClient channel = publisherChannels.remove(request.getIdentifier());
if (channel != null) {
eventloop.disconnect(channel);
}
dl.reset();
message = ("Request sent for processing: " + request).getBytes();
}
final byte[] tuple = PayloadTuple.getSerializedTuple(0, message.length);
System.arraycopy(message, 0, tuple, tuple.length - message.length, message.length);
if (ctx.write(tuple)) {
ctx.write();
} else {
logger.error("Failed to deliver reset ack message. {} send buffers are full.", ctx);
throw new RuntimeException("Failed to deliver reset ack message. " + ctx + "send buffers are full.");
}
}
use of com.datatorrent.bufferserver.internal.DataList 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.DataList in project apex-core by apache.
the class Server method handlePurgeRequest.
private void handlePurgeRequest(PurgeRequestTuple request, final AbstractLengthPrependerClient ctx) throws IOException {
DataList dl;
dl = publisherBuffers.get(request.getIdentifier());
byte[] message;
if (dl == null) {
message = ("Invalid identifier '" + request.getIdentifier() + "'").getBytes();
} else {
dl.purge((long) request.getBaseSeconds() << 32 | request.getWindowId());
message = ("Request sent for processing: " + request).getBytes();
}
final byte[] tuple = PayloadTuple.getSerializedTuple(0, message.length);
System.arraycopy(message, 0, tuple, tuple.length - message.length, message.length);
if (ctx.write(tuple)) {
ctx.write();
} else {
logger.error("Failed to deliver purge ack message. {} send buffers are full.", ctx);
throw new RuntimeException("Failed to deliver purge ack message. " + ctx + "send buffers are full.");
}
}
use of com.datatorrent.bufferserver.internal.DataList 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