KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > statetransfer > StateTransferFactory


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.cache.statetransfer;
8
9 import org.jboss.cache.CacheImpl;
10 import org.jboss.cache.Fqn;
11 import org.jboss.cache.Version;
12
13 import java.io.IOException JavaDoc;
14 import java.io.ObjectInputStream JavaDoc;
15
16 /**
17  * Factory class able to create {@link StateTransferGenerator} and
18  * {@link StateTransferIntegrator} instances.
19  *
20  * @author <a HREF="brian.stansberry@jboss.com">Brian Stansberry</a>
21  * @version $Revision: 1.13 $
22  */

23 public abstract class StateTransferFactory
24 {
25    private static final short RV_200 = Version.getVersionShort("2.0.0");
26
27    /**
28     * Gets the StateTransferGenerator able to handle the given cache instance.
29     *
30     * @param cache the cache
31     * @return the {@link StateTransferGenerator}
32     * @throws IllegalStateException if the cache's ReplicationVersion is < 2.0.0
33     */

34    public static StateTransferGenerator
35    getStateTransferGenerator(CacheImpl cache)
36    {
37       short version = cache.getConfiguration().getReplicationVersion();
38
39       // Compiler won't let me use a switch
40

41       if (version < RV_200 && version > 0) // <= 0 is actually a version > 15.31.63
42
throw new IllegalStateException JavaDoc("State transfer with cache replication version < 2.0.0 not supported");
43       else
44          return new DefaultStateTransferGenerator(cache); // current default
45
}
46
47    public static StateTransferIntegrator getStateTransferIntegrator(ObjectInputStream JavaDoc in, Fqn fqn, CacheImpl cache)
48            throws Exception JavaDoc
49    {
50       short version = 0;
51       try
52       {
53          version = in.readShort();
54       }
55       catch (IOException JavaDoc io)
56       {
57          // something is wrong with this stream, close it
58
try
59          {
60             in.close();
61          }
62          catch (IOException JavaDoc ignored) {}
63          throw new IllegalStateException JavaDoc("Stream corrupted ", io);
64       }
65
66       // Compiler won't let me use a switch
67

68       if (version < RV_200 && version > 0) // <= 0 is actually a version > 15.31.63
69
throw new IllegalStateException JavaDoc("State transfer with cache replication version < 2.0.0 not supported");
70       else
71          return new DefaultStateTransferIntegrator(fqn, cache); // current default
72
}
73
74 }
75
Popular Tags