Hi,

To be able to deserialize the objects you need to use Java Serialization, and 
the bytestrings contain the data in the order that you wrote it. One bytestring 
might contain both objects, or in the case of large objects, only part of an 
object. Writing the object output stream straight into the remote server is not 
a good idea, and you would probably be better off with a protocol that has some 
proper framing that you can easily interpret without doing the deserialization.

Personally I would use akka-http or spray and expose the cache as a REST 
service. Then you could post your key value pairs in a form, and easily pick 
out the parts on the other end.

B/

On 2 March 2015 at 14:05:15, Ömer Faruk Gül ([email protected]) wrote:

Hi,

I'm trying to transfer serialized java objects to an Actor.

What I want to do is to transfer a java serialised object with a key. (Think of 
it is like a key value cache) The server is written with Akka Actors and the 
client is Java.

On the actor side I get the "ByteString" objects, and when I immediately send 
them to Java client I can read them. There is no problem with this. The problem 
is, I want to know which keys and objects are received on the actor level. But 
I only get ByteString, and I don't know which of them is the key or the object. 
Is there kind of a delimiter which I should check, like "now I'm receiving the 
key, and now I receive the related object"?

The example java code I'm using:

InetAddress address = InetAddress.getByName("127.0.0.1");
Socket socket = new Socket(address, 7000);

ObjectOutputStream outputStream = new 
ObjectOutputStream(socket.getOutputStream());
outputStream.writeObject("key1");
outputStream.writeObject(user);


ObjectInputStream inputStream = new ObjectInputStream(socket.getInputStream());

String str2 = (String)inputStream.readObject();
System.out.println("Received string2 object: "+str2);

User user2 = (User)inputStream.readObject();
System.out.println("Received user2 object: "+user2.fullName());



And my data handler is the example given on the Akka.io socket introduction:

class SimplisticHandler extends Actor with ActorLogging {

 override def preStart() = {
 log.info("SimplisticHandler started!")
 }

 def receive = {
 case Received(data) =>
 log.info("Received data: "+data)
 sender() ! Write(data)
 case PeerClosed => context.stop(self)
 }

 override def postStop() = {
 log.info("SimplisticHandler stopped!")
 }
}




--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
--
Björn Antonsson
Typesafe Inc. – Reactive Apps on the JVM
twitter: bantonsson

JOIN US. REGISTER TODAY!
Scala
Days
March 16th-18th,
San Francisco

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to