Changed code as requested by @CyB3RC0nN0R
This commit is contained in:
parent
1d35de3a39
commit
b7af8aa7bd
@ -24,8 +24,6 @@ import envoy.event.Event;
|
|||||||
*/
|
*/
|
||||||
public class ObjectMessageProcessor implements IMessageProcessor {
|
public class ObjectMessageProcessor implements IMessageProcessor {
|
||||||
|
|
||||||
private long currentUserID = 0;// temporary
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(Message message, WriteProxy writeProxy) {
|
public void process(Message message, WriteProxy writeProxy) {
|
||||||
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(message.sharedArray, message.offset + 4, message.length - 4))) {
|
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(message.sharedArray, message.offset + 4, message.length - 4))) {
|
||||||
@ -51,36 +49,55 @@ public class ObjectMessageProcessor implements IMessageProcessor {
|
|||||||
* @since Envoy Server Standalone v0.1-alpha
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
*/
|
*/
|
||||||
private void handleObject(Message request, WriteProxy writeProxy, Object obj) throws IllegalArgumentException {
|
private void handleObject(Message request, WriteProxy writeProxy, Object obj) throws IllegalArgumentException {
|
||||||
boolean responseToSameSocket = false;
|
|
||||||
|
long currentUserID = 0; // TODO temporary. Only for testing purposes
|
||||||
|
boolean responseToSameSocket = false, immediateResponse = true;
|
||||||
Object usage;
|
Object usage;
|
||||||
|
|
||||||
|
// determining the type of the incoming object
|
||||||
if (obj instanceof envoy.data.Message) {// if object is Message
|
if (obj instanceof envoy.data.Message) {// if object is Message
|
||||||
envoy.data.Message cast = (envoy.data.Message) obj;
|
envoy.data.Message cast = (envoy.data.Message) obj;
|
||||||
usage = cast.getClass();
|
usage = cast.getClass();
|
||||||
|
immediateResponse = isRecipientAvailable(-1); // TODO replace with wanted clientID
|
||||||
} else if (obj instanceof Event) {// if object is Event
|
} else if (obj instanceof Event) {// if object is Event
|
||||||
usage = (Event<?>) obj;
|
usage = (Event<?>) obj;
|
||||||
|
immediateResponse = isRecipientAvailable(-1); // TODO replace with wanted clientID
|
||||||
} else if (obj instanceof LoginCredentials) {// if object is LoginCredential
|
} else if (obj instanceof LoginCredentials) {// if object is LoginCredential
|
||||||
responseToSameSocket = true;
|
responseToSameSocket = true;
|
||||||
LoginCredentials cast = (LoginCredentials) obj;
|
LoginCredentials cast = (LoginCredentials) obj;
|
||||||
usage = new User(currentUserID++, cast.getName());
|
usage = new User(currentUserID++, cast.getName());
|
||||||
} else throw new IllegalArgumentException();
|
} else throw new IllegalArgumentException();
|
||||||
|
|
||||||
Message response = writeProxy.getMessage();
|
// handling of incoming object
|
||||||
if (responseToSameSocket) {
|
if (immediateResponse) {
|
||||||
response.socketId = request.socketId;
|
Message response = writeProxy.getMessage();
|
||||||
} else {
|
if (responseToSameSocket) {
|
||||||
response.socketId = -0;// TODO temporary.Needs to be replaced
|
response.socketId = request.socketId;
|
||||||
return;
|
} else {
|
||||||
|
response.socketId = -0;// TODO temporary.Needs to be replaced
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Serialize object to byte array
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
try (ObjectOutputStream oout = new ObjectOutputStream(baos)) {
|
||||||
|
oout.writeObject(usage);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
byte[] objBytes = baos.toByteArray();
|
||||||
|
response.writeToMessage(objBytes);
|
||||||
|
writeProxy.enqueue(response);
|
||||||
}
|
}
|
||||||
// Serialize object to byte array
|
}
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
try (ObjectOutputStream oout = new ObjectOutputStream(baos)) {
|
|
||||||
oout.writeObject(usage);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
byte[] objBytes = baos.toByteArray();
|
|
||||||
response.writeToMessage(objBytes);
|
|
||||||
writeProxy.enqueue(response);
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method determines if the recipient is online
|
||||||
|
*
|
||||||
|
* @param otherClientID the ID of the recipient
|
||||||
|
* @return true, if the recipient is online
|
||||||
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
|
*/
|
||||||
|
private boolean isRecipientAvailable(long otherClientID) {
|
||||||
|
return false;// TODO needs to be adapted to return true if the wanted client is online
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user