use of com.jme3.network.Message in project jmonkeyengine by jMonkeyEngine.
the class GZIPSerializer method readObject.
@SuppressWarnings("unchecked")
public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException {
try {
GZIPCompressedMessage result = new GZIPCompressedMessage();
byte[] byteArray = new byte[data.remaining()];
data.get(byteArray);
GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(byteArray));
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] tmp = new byte[9012];
int read;
while (in.available() > 0 && ((read = in.read(tmp)) > 0)) {
out.write(tmp, 0, read);
}
result.setMessage((Message) Serializer.readClassAndObject(ByteBuffer.wrap(out.toByteArray())));
return (T) result;
} catch (Exception e) {
e.printStackTrace();
throw new IOException(e.toString());
}
}
use of com.jme3.network.Message in project jmonkeyengine by jMonkeyEngine.
the class MessageProtocol method createMessage.
/**
* Creates a message from the properly sized byte buffer
* and adds it to the messages queue.
*/
protected void createMessage(ByteBuffer buffer) {
try {
Object obj = Serializer.readClassAndObject(buffer);
Message m = (Message) obj;
messages.add(m);
} catch (IOException e) {
throw new RuntimeException("Error deserializing object, class ID:" + buffer.getShort(0), e);
}
}
use of com.jme3.network.Message in project jmonkeyengine by jMonkeyEngine.
the class NioEndpoint method close.
public void close(boolean flushData) {
if (flushData) {
closing = true;
// Enqueue a close marker message to let the server
// know we should close
send(CLOSE_MARKER, false, true);
return;
}
try {
// Note: even though we may be disconnected from the socket.isConnected()
// standpoint, it's still safest to tell the kernel so that it can be sure
// to stop managing us gracefully.
kernel.closeEndpoint(this);
} catch (IOException e) {
throw new KernelException("Error closing endpoint for socket:" + socket, e);
}
}
use of com.jme3.network.Message in project jmonkeyengine by jMonkeyEngine.
the class RpcConnection method callAndWait.
/**
* Performs a remote procedure call with the specified arguments and waits
* for the response. Both the outbound message and inbound response will
* be sent on the specified channel.
*/
public Object callAndWait(byte channel, short objId, short procId, Object... args) {
RpcCallMessage msg = new RpcCallMessage(sequenceNumber.getAndIncrement(), channel, objId, procId, args);
// Need to register an object so we can wait for the response.
// ...before we send it. Just in case.
ResponseHolder holder = new ResponseHolder(msg);
responses.put(msg.getMessageId(), holder);
if (log.isLoggable(Level.FINEST)) {
log.log(Level.FINEST, "Sending:{0} on channel:{1}", new Object[] { msg, channel });
}
// so it doesn't do the check.
if (channel >= 0) {
connection.send(channel, msg);
} else {
connection.send(msg);
}
return holder.getResponse();
}
use of com.jme3.network.Message in project jmonkeyengine by jMonkeyEngine.
the class RpcHostedService method onInitialize.
/**
* Used internally to setup the message delegator that will
* handle HostedConnection specific messages and forward them
* to that connection's RpcConnection.
*/
@Override
protected void onInitialize(HostedServiceManager serviceManager) {
Server server = serviceManager.getServer();
// A general listener for forwarding the messages
// to the client-specific handler
this.delegator = new SessionDataDelegator(RpcConnection.class, ATTRIBUTE_NAME, true);
server.addMessageListener(delegator, delegator.getMessageTypes());
if (log.isLoggable(Level.FINEST)) {
log.log(Level.FINEST, "Registered delegator for message types:{0}", Arrays.asList(delegator.getMessageTypes()));
}
}
Aggregations