org.snapscript.studio.agent.local.LocalMessageProducer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
package org.snapscript.studio.agent.local;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import org.snapscript.studio.agent.local.message.AttachRequest;
import org.snapscript.studio.agent.local.message.AttachResponse;
import org.snapscript.studio.agent.local.message.DetachRequest;
import org.snapscript.studio.agent.local.message.DetachResponse;
public class LocalMessageProducer {
public LocalMessageProducer(){
super();
}
public AttachResponse attach(Socket socket, AttachRequest request) throws Exception {
OutputStream stream = socket.getOutputStream();
InputStream in = socket.getInputStream();
ObjectOutputStream output = new ObjectOutputStream(stream);
ObjectInputStream input = new ObjectInputStream(in);
output.writeObject(request);
return (AttachResponse)input.readObject();
}
public DetachResponse detach(Socket socket, DetachRequest request) throws Exception {
OutputStream out = socket.getOutputStream();
InputStream in = socket.getInputStream();
ObjectOutputStream output = new ObjectOutputStream(out);
ObjectInputStream input = new ObjectInputStream(in);
output.writeObject(request);
return (DetachResponse)input.readObject();
}
}