|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
Marshaller.java | - | - | - | - |
|
1 | package org.jboss.cache.marshall; | |
2 | ||
3 | import org.jboss.cache.Fqn; | |
4 | import org.jgroups.blocks.RpcDispatcher; | |
5 | ||
6 | import java.io.InputStream; | |
7 | import java.io.ObjectInputStream; | |
8 | import java.io.ObjectOutputStream; | |
9 | ||
10 | /** | |
11 | * A marshaller is a class that is able to marshall and unmarshall objects efficiently. | |
12 | * <p/> | |
13 | * The reason why this is implemented specially in JBoss Cache rather than resorting to | |
14 | * Java serialization or even the more efficient JBoss serialization is that a lot of efficiency | |
15 | * can be gained when a majority of the serialization that occurs has to do with a small set | |
16 | * of known types such as {@link org.jboss.cache.Fqn} or {@link MethodCall}, and class type information | |
17 | * can be replaced with simple magic numbers. | |
18 | * <p/> | |
19 | * Unknown types (typically user data) falls back to JBoss serialization. | |
20 | * <p/> | |
21 | * In addition, using a marshaller allows adding additional data to the byte stream, such as context | |
22 | * class loader information on which class loader to use to deserialize the object stream, or versioning | |
23 | * information to allow streams to interoperate between different versions of JBoss Cache (see {@link VersionAwareMarshaller} | |
24 | * <p/> | |
25 | * This interface implements the JGroups building-block interface {@link org.jgroups.blocks.RpcDispatcher.Marshaller} which | |
26 | * is used to marshall {@link MethodCall}s, their parameters and their response values. | |
27 | * <p/> | |
28 | * The interface is also used by the {@link org.jboss.cache.loader.CacheLoader} framework to efficiently serialize data to be persisted, as well as | |
29 | * the {@link org.jboss.cache.statetransfer.StateTransferManager} when serializing the cache for transferring state en-masse. | |
30 | * | |
31 | * @author <a href="mailto://manik@jboss.org">Manik Surtani</a> | |
32 | * @since 2.0.0 | |
33 | */ | |
34 | public interface Marshaller extends RpcDispatcher.Marshaller | |
35 | { | |
36 | /** | |
37 | * Marshalls an object to a given {@link ObjectOutputStream} | |
38 | * | |
39 | * @param obj object to marshall | |
40 | * @param out stream to marshall to | |
41 | * @throws Exception | |
42 | */ | |
43 | void objectToObjectStream(Object obj, ObjectOutputStream out) throws Exception; | |
44 | ||
45 | /** | |
46 | * Unmarshalls an object from an {@link ObjectInputStream} | |
47 | * | |
48 | * @param in stream to unmarshall from | |
49 | * @throws Exception | |
50 | */ | |
51 | Object objectFromObjectStream(ObjectInputStream in) throws Exception; | |
52 | ||
53 | /** | |
54 | * Unmarshalls an object from an {@link java.io.InputStream} | |
55 | * | |
56 | * @param is stream to unmarshall from | |
57 | * @return Object from stream passed in. | |
58 | * @throws Exception | |
59 | */ | |
60 | Object objectFromStream(InputStream is) throws Exception; | |
61 | ||
62 | /** | |
63 | * Overloaded form of {@link #objectToObjectStream(Object,java.io.ObjectOutputStream)} which adds a hint to the {@link Fqn} region | |
64 | * | |
65 | * @param obj object to marshall | |
66 | * @param region fqn that this object pertains to | |
67 | * @param out stream to marshall to | |
68 | * @throws Exception | |
69 | */ | |
70 | void objectToObjectStream(Object obj, ObjectOutputStream out, Fqn region) throws Exception; | |
71 | } |
|