org.nakedobjects.nos.remote.encoded.EncodingClientConnection Maven / Gradle / Ivy
package org.nakedobjects.nos.remote.encoded;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.SocketException;
import org.apache.log4j.Logger;
import org.nakedobjects.noa.util.ByteDecoder;
import org.nakedobjects.noa.util.ByteEncoder;
import org.nakedobjects.nof.core.util.DebugByteDecoder;
import org.nakedobjects.nof.core.util.DebugByteEncoder;
import org.nakedobjects.nos.remote.command.Request;
import org.nakedobjects.nos.remote.command.socket.ClientConnection;
class EncodingClientConnection extends ClientConnection {
private static final Logger LOG = Logger.getLogger(EncodingClientConnection.class);
private ByteEncoder encoder;
private ByteDecoder decoder;
protected void openStreams(InputStream input, OutputStream output) throws IOException {
encoder = new DebugByteEncoder(output);
decoder = new DebugByteDecoder(input);
}
protected Object request(final Request request) throws IOException {
LOG.debug("sending request " + request);
try {
write(request);
} catch (SocketException e) {
reconnect();
write(request);
}
Object object = decoder.getObject();
LOG.debug("response received: " + object);
decoder.end();
return object;
}
private void write(final Request request) throws IOException {
encoder.add(request.getClass().getName());
request.encode(encoder);
encoder.end();
}
}
// Copyright (c) Naked Objects Group Ltd.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy