Re: Serialization Snag
Was the 'other side' (Berkely DB) in a separate process / machine? Or part of the same jvm? If separate, what clojure knowledge / libraries did the other side have? I assume there was serialization across or else you wouldnt have gotten the PersistentMap error. And sounds like your passing the CLASS itself and not a specific object instance? When loading the above code, I can now pass myLib.CalendarComparator as class to the Berkeley API and no longer get the error that PersistentMap is not serializable. Thanks, you've given me some more ideas to play with --n --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Serialization Snag
On Sep 18, 8:51 am, noahr [EMAIL PROTECTED] wrote: Was the 'other side' (Berkely DB) in a separate process / machine? Or part of the same jvm? Same JVM; I am running my Clojure application on the server and it persists and retrieves data from Berkeley. It currently exposes an API for a client application in JSON. If separate, what clojure knowledge / libraries did the other side have? I assume there was serialization across or else you wouldnt have gotten the PersistentMap error. And sounds like your passing the CLASS itself and not a specific object instance? Right; I am not persisting JVM instances; but I needed to pass a CLASS to one Berkeley DB API because I have a custom sort order algorithm for storage (and for some reason Berkeley demanded that instances of the class be serializable). When loading the above code, I can now pass myLib.CalendarComparator as class to the Berkeley API and no longer get the error that PersistentMap is not serializable. Thanks, you've given me some more ideas to play with Cool. Hope you come right. Joubert --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Serialization Snag
Hello noahr, I have created a library for myself to do persistence in Clojure to Berkeley DB. I generally leverage Clojure's reader support for (de)serialization. However, in one instance I had to implement a particular interface and pass that class as parameter to the Berkeley API. At first I, like you, used the proxy form, and, even though I indicated implementation of the required interface, I also got the error message that PersistentMap is not serializable. After some doodling I found a solution that obviates the need to write Java code. Simply use the get-xxx-class-xxx family of forms. For example, in my case I needed to supply a class that implements java.util.Comparator (with concomitant serializable requirements on the Berkeley API side). I did it roughly like so: (in-ns 'myLib.CalendarComparator) (clojure/refer 'clojure) (defn- deserialize [bytes] (let [stream (ObjectInputStream. (ByteArrayInputStream. bytes))] (let [result (.readObject stream)] (.close stream) result))) (defn compare [time1bytes time2bytes] (let [t1 (deserialize time1bytes) t2 (deserialize time2bytes)] (if (.before t1 t2) -1 (if (.after t1 t2) 1 0 ;;; Declare class and make available as myLib.CalendarComparator (try (clojure/gen-and-load-class 'mylib.CalendarComparator :implements [java.util.Comparator]) (catch java.lang.LinkageError e)) = When loading the above code, I can now pass myLib.CalendarComparator as class to the Berkeley API and no longer get the error that PersistentMap is not serializable. Joubert On Sep 12, 12:59 pm, noahr [EMAIL PROTECTED] wrote: Well digging into it more, I've since realized the whole approach I was taking is misguided anyway, as serialization appears to be for marshaling the data of already defined classes. What I was really trying to do was create new classes (java or clojure), and stream them across the network, and have them executed on other side by a system that only knew the 'parent' class or interface. But I believe this will require custom class loading from bytes on the other side. I still suspect though there will be issues when trying to mix dynamic clojure-created classes with serialization, due to its data types not being serializable. Some of the customizations for java serialization might offer a way out, but uncertain.. Also, I don't have clojure on both sides; unfamiliar with thrift/ protocol buffers, will look them up. Thx --n If you've got Clojure available on both ends, you can serialize with (pr-str...) and deserialize with (read...). Only works with pure- Clojure data structures, tho. Maybe you could use Clojure to generate a native Java collection like ArrayList and serialize that. Another option is something like Thrift or Protocol Buffers. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Serialization Snag
I've hit a problem trying to serialize an object from one (clojure) server to another (java). I was *hoping* to simply use (PROXY) to implement the object I want to send in clojure, and serialize that across the stream. Unfortunately java barfs about: java.io.NotSerializableException: clojure.lang.PersistentHashMap $LeafNode which I interpret to mean that the internal clojure implementation is NOT serializable, due to its data structures. So it looks like I will have to implement the object I want to send across the stream in Java, not clojure (sigh) Any ideas anyone? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Serialization Snag
On Sep 12, 8:55 am, noahr [EMAIL PROTECTED] wrote: So it looks like I will have to implement the object I want to send across the stream in Java, not clojure (sigh) Any ideas anyone? If you've got Clojure available on both ends, you can serialize with (pr-str...) and deserialize with (read...). Only works with pure- Clojure data structures, tho. Maybe you could use Clojure to generate a native Java collection like ArrayList and serialize that. Another option is something like Thrift or Protocol Buffers. -Stuart --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Serialization Snag
You wouldn't be able to execute any clojure created class or proxy without having clojure available on the other side. You would have to stream all of the dynamic classes that clojure creates (and each fn is also a class), but also have available the clojure.lang stuff it depends on to load and run. I don't know about Thrift, but PB is just another way of streaming data. If you can get clojure on both sides, you could not only stream the clojure data structures, but code text also (assuming the environment is secure). Code is data :). -Mike On Sep 12, 9:59 am, noahr [EMAIL PROTECTED] wrote: Well digging into it more, I've since realized the whole approach I was taking is misguided anyway, as serialization appears to be for marshaling the data of already defined classes. What I was really trying to do was create new classes (java or clojure), and stream them across the network, and have them executed on other side by a system that only knew the 'parent' class or interface. But I believe this will require custom class loading from bytes on the other side. I still suspect though there will be issues when trying to mix dynamic clojure-created classes with serialization, due to its data types not being serializable. Some of the customizations for java serialization might offer a way out, but uncertain.. Also, I don't have clojure on both sides; unfamiliar with thrift/ protocol buffers, will look them up. Thx --n If you've got Clojure available on both ends, you can serialize with (pr-str...) and deserialize with (read...). Only works with pure- Clojure data structures, tho. Maybe you could use Clojure to generate a native Java collection like ArrayList and serialize that. Another option is something like Thrift or Protocol Buffers. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---