use of org.voltdb.messaging.LocalMailbox in project voltdb by VoltDB.
the class OpsAgent method registerMailbox.
public void registerMailbox(final HostMessenger hostMessenger, final long hsId) {
m_messenger = hostMessenger;
hostMessenger.generateMailboxId(hsId);
m_mailbox = new LocalMailbox(hostMessenger, hsId) {
@Override
public void deliver(final VoltMessage message) {
m_es.submit(new Runnable() {
@Override
public void run() {
handleMailboxMessage(message);
}
});
}
};
hostMessenger.registerMailbox(m_mailbox);
}
use of org.voltdb.messaging.LocalMailbox in project voltdb by VoltDB.
the class ExportGeneration method createAndRegisterAckMailboxes.
private void createAndRegisterAckMailboxes(final Set<Integer> localPartitions, HostMessenger messenger) {
m_mailboxesZKPath = VoltZK.exportGenerations + "/" + m_timestamp + "/" + "mailboxes";
m_mbox = new LocalMailbox(messenger) {
@Override
public void deliver(VoltMessage message) {
if (message instanceof BinaryPayloadMessage) {
BinaryPayloadMessage bpm = (BinaryPayloadMessage) message;
ByteBuffer buf = ByteBuffer.wrap(bpm.m_payload);
final int partition = buf.getInt();
final int length = buf.getInt();
byte[] stringBytes = new byte[length];
buf.get(stringBytes);
String signature = new String(stringBytes, Constants.UTF8ENCODING);
final long ackUSO = buf.getLong();
final boolean runEveryWhere = (buf.getShort() == (short) 1);
final Map<String, ExportDataSource> partitionSources = m_dataSourcesByPartition.get(partition);
if (partitionSources == null) {
exportLog.error("Received an export ack for partition " + partition + " which does not exist on this node, partitions = " + m_dataSourcesByPartition);
return;
}
final ExportDataSource eds = partitionSources.get(signature);
if (eds == null) {
exportLog.warn("Received an export ack for partition " + partition + " source signature " + signature + " which does not exist on this node, sources = " + partitionSources);
return;
}
try {
eds.ack(ackUSO, runEveryWhere);
} catch (RejectedExecutionException ignoreIt) {
// ignore it: as it is already shutdown
}
} else {
exportLog.error("Receive unexpected message " + message + " in export subsystem");
}
}
};
messenger.createMailbox(null, m_mbox);
for (Integer partition : localPartitions) {
final String partitionDN = m_mailboxesZKPath + "/" + partition;
ZKUtil.asyncMkdirs(messenger.getZK(), partitionDN);
ZKUtil.StringCallback cb = new ZKUtil.StringCallback();
messenger.getZK().create(partitionDN + "/" + m_mbox.getHSId(), null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL, cb, null);
}
ListenableFuture<?> fut = m_childUpdatingThread.submit(new Runnable() {
@Override
public void run() {
List<Pair<Integer, ZKUtil.ChildrenCallback>> callbacks = new ArrayList<Pair<Integer, ZKUtil.ChildrenCallback>>();
for (Integer partition : localPartitions) {
ZKUtil.ChildrenCallback callback = new ZKUtil.ChildrenCallback();
messenger.getZK().getChildren(m_mailboxesZKPath + "/" + partition, constructMailboxChildWatcher(messenger), callback, null);
callbacks.add(Pair.of(partition, callback));
}
for (Pair<Integer, ZKUtil.ChildrenCallback> p : callbacks) {
final Integer partition = p.getFirst();
List<String> children = null;
try {
children = p.getSecond().getChildren();
} catch (InterruptedException e) {
Throwables.propagate(e);
} catch (KeeperException e) {
Throwables.propagate(e);
}
ImmutableList.Builder<Long> mailboxes = ImmutableList.builder();
for (String child : children) {
if (child.equals(Long.toString(m_mbox.getHSId())))
continue;
mailboxes.add(Long.valueOf(child));
}
ImmutableList<Long> mailboxHsids = mailboxes.build();
for (ExportDataSource eds : m_dataSourcesByPartition.get(partition).values()) {
eds.updateAckMailboxes(Pair.of(m_mbox, mailboxHsids));
}
}
}
});
try {
fut.get();
} catch (Throwable t) {
Throwables.propagate(t);
}
}
Aggregations