use of org.apache.catalina.tribes.io.ChannelData in project tomcat by apache.
the class StaticMembershipInterceptor method sendMemberMessage.
protected void sendMemberMessage(Member[] members, byte[] message) throws ChannelException {
if (members == null || members.length == 0)
return;
ChannelData data = new ChannelData(true);
data.setAddress(getLocalMember(false));
data.setTimestamp(System.currentTimeMillis());
data.setOptions(getOptionFlag());
data.setMessage(new XByteBuffer(message, false));
super.sendMessage(members, data, null);
}
use of org.apache.catalina.tribes.io.ChannelData in project tomcat by apache.
the class NonBlockingCoordinator method createData.
public ChannelData createData(CoordinationMessage msg, Member local) {
msg.write();
ChannelData data = new ChannelData(true);
data.setAddress(local);
data.setMessage(msg.getBuffer());
data.setOptions(Channel.SEND_OPTIONS_USE_ACK);
data.setTimestamp(System.currentTimeMillis());
return data;
}
use of org.apache.catalina.tribes.io.ChannelData in project tomcat by apache.
the class McastServiceImpl method memberBroadcastsReceived.
private void memberBroadcastsReceived(final byte[] b) {
if (log.isTraceEnabled())
log.trace("Mcast received broadcasts.");
XByteBuffer buffer = new XByteBuffer(b, true);
if (buffer.countPackages(true) > 0) {
int count = buffer.countPackages();
final ChannelData[] data = new ChannelData[count];
for (int i = 0; i < count; i++) {
try {
data[i] = buffer.extractPackage(true);
} catch (IllegalStateException ise) {
log.debug("Unable to decode message.", ise);
}
}
Runnable t = new Runnable() {
@Override
public void run() {
String name = Thread.currentThread().getName();
try {
Thread.currentThread().setName("Membership-MemberAdded.");
for (int i = 0; i < data.length; i++) {
try {
if (data[i] != null && !member.equals(data[i].getAddress())) {
msgservice.messageReceived(data[i]);
}
} catch (Throwable t) {
if (t instanceof ThreadDeath) {
throw (ThreadDeath) t;
}
if (t instanceof VirtualMachineError) {
throw (VirtualMachineError) t;
}
log.error(sm.getString("mcastServiceImpl.unableReceive.broadcastMessage"), t);
}
}
} finally {
Thread.currentThread().setName(name);
}
}
};
executor.execute(t);
}
}
use of org.apache.catalina.tribes.io.ChannelData in project tomcat by apache.
the class NioSenderTest method getMessage.
public synchronized ChannelData getMessage(Member mbr) {
String msg = "Thread-" + Thread.currentThread().getName() + " Message:" + inc();
ChannelData data = new ChannelData(true);
data.setMessage(new XByteBuffer(msg.getBytes(), false));
data.setAddress(mbr);
return data;
}
use of org.apache.catalina.tribes.io.ChannelData in project tomcat by apache.
the class SocketNioReceive method main.
public static void main(String[] args) throws Exception {
Member mbr = new MemberImpl("localhost", 9999, 0);
ChannelData data = new ChannelData();
data.setAddress(mbr);
byte[] buf = new byte[8192 * 4];
data.setMessage(new XByteBuffer(buf, false));
buf = XByteBuffer.createDataPackage(data);
len = buf.length;
NioReceiver receiver = new NioReceiver();
receiver.setPort(9999);
receiver.setHost("localhost");
MyList list = new MyList();
receiver.setMessageListener(list);
receiver.start();
System.out.println("Listening on 9999");
while (true) {
try {
synchronized (mutex) {
mutex.wait(5000);
if (start != 0) {
System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds, messages " + count + " accepts " + accept + ", total " + mb + " MB.");
}
}
} catch (Throwable x) {
x.printStackTrace();
}
}
}
Aggregations