use of games.strategy.net.MessageHeader in project triplea by triplea-game.
the class Decoder method loop.
private void loop() {
while (running) {
try {
final SocketReadData data = reader.take();
if (data == null || !running) {
continue;
}
try {
final MessageHeader header = IoUtils.readFromMemory(data.getData(), is -> {
try {
return readMessageHeader(data.getChannel(), objectStreamFactory.create(is));
} catch (final ClassNotFoundException e) {
throw new IOException(e);
}
});
// make sure we are still open
final Socket s = data.getChannel().socket();
if (!running || s == null || s.isInputShutdown()) {
continue;
}
final QuarantineConversation converstation = quarantine.get(data.getChannel());
if (converstation != null) {
sendQuarantine(data.getChannel(), converstation, header);
} else {
if (nioSocket.getLocalNode() == null) {
throw new IllegalStateException("we are writing messages, but no local node");
}
if (header.getFrom() == null) {
throw new IllegalArgumentException("Null from:" + header);
}
nioSocket.messageReceived(header, data.getChannel());
}
} catch (final IOException | RuntimeException e) {
// we are reading from memory here
// there should be no network errors, something
// is odd
logger.log(Level.SEVERE, "error reading object", e);
errorReporter.error(data.getChannel(), e);
}
} catch (final InterruptedException e) {
// otherwise re-interrupt this thread and keep running
if (running) {
Thread.currentThread().interrupt();
}
}
}
}
use of games.strategy.net.MessageHeader in project triplea by triplea-game.
the class ServerQuarantineConversation method send.
private void send(final Serializable object) {
// this messenger is quarantined, so to and from dont matter
final MessageHeader header = new MessageHeader(Node.NULL_NODE, Node.NULL_NODE, object);
socket.send(channel, header);
}
use of games.strategy.net.MessageHeader in project triplea by triplea-game.
the class Decoder method readMessageHeader.
private MessageHeader readMessageHeader(final SocketChannel channel, final ObjectInputStream objectInput) throws IOException, ClassNotFoundException {
final INode to;
if (objectInput.read() == 1) {
to = null;
} else {
if (objectInput.read() == 1) {
// this may be null if we
// have not yet fully joined the network
to = nioSocket.getLocalNode();
} else {
to = new Node();
((Node) to).readExternal(objectInput);
}
}
final INode from;
final int readMark = objectInput.read();
if (readMark == 1) {
from = nioSocket.getRemoteNode(channel);
} else if (readMark == 2) {
from = null;
} else {
from = new Node();
((Node) from).readExternal(objectInput);
}
final Serializable message;
final byte type = (byte) objectInput.read();
if (type != Byte.MAX_VALUE) {
final Externalizable template = getTemplate(type);
template.readExternal(objectInput);
message = template;
} else {
message = (Serializable) objectInput.readObject();
}
return new MessageHeader(to, from, message);
}
use of games.strategy.net.MessageHeader in project triplea by triplea-game.
the class ClientQuarantineConversation method send.
private void send(final Serializable object) {
// this messenger is quarantined, so to and from dont matter
final MessageHeader header = new MessageHeader(Node.NULL_NODE, Node.NULL_NODE, object);
socket.send(channel, header);
}
Aggregations