View Javadoc

1   /***
2    *  Copyright 2003-2010 Terracotta, Inc.
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  
17  package net.sf.ehcache.terracotta;
18  
19  import net.sf.ehcache.Ehcache;
20  import net.sf.ehcache.cluster.CacheCluster;
21  import net.sf.ehcache.event.CacheEventListener;
22  import net.sf.ehcache.store.Store;
23  import net.sf.ehcache.transaction.SoftLockFactory;
24  import net.sf.ehcache.transaction.TransactionIDFactory;
25  import net.sf.ehcache.writer.writebehind.WriteBehind;
26  
27  /***
28   * A {@link ClusteredInstanceFactory} implementation that delegates all operations to an underlying delegate except for the following
29   * operations:
30   *<ul>
31   *<li>{@link #getTopology()} : Delegates to the {@link TerracottaClient#getCacheCluster()}</li>
32   *</ul>
33   *
34   * @author Abhishek Sanoujam
35   *
36   */
37  public class ClusteredInstanceFactoryWrapper implements ClusteredInstanceFactory {
38  
39      private final TerracottaClient client;
40      private final ClusteredInstanceFactory delegate;
41  
42      /***
43       * Constructor accepting the TerracottaClient and the actual factory
44       *
45       * @param client
46       * @param delegate
47       */
48      public ClusteredInstanceFactoryWrapper(TerracottaClient client, ClusteredInstanceFactory delegate) {
49          this.client = client;
50          this.delegate = delegate;
51  
52      }
53  
54      /***
55       * Returns the actual underlying factory
56       * @return the actual underlying factory
57       */
58      protected ClusteredInstanceFactory getActualFactory() {
59          return delegate;
60      }
61  
62      /***
63       * {@inheritDoc}
64       */
65      public CacheCluster getTopology() {
66          client.waitUntilRejoinComplete();
67          return client.getCacheCluster();
68      }
69  
70      // all methods below delegate to the real factory
71  
72      /***
73       * {@inheritDoc}
74       */
75      public String getUUID() {
76          client.waitUntilRejoinComplete();
77          return delegate.getUUID();
78      }
79  
80      /***
81       * {@inheritDoc}
82       */
83      public CacheEventListener createEventReplicator(Ehcache cache) {
84          client.waitUntilRejoinComplete();
85          return delegate.createEventReplicator(cache);
86      }
87  
88      /***
89       * {@inheritDoc}
90       */
91      public Store createStore(Ehcache cache) {
92          client.waitUntilRejoinComplete();
93          return delegate.createStore(cache);
94      }
95  
96      /***
97       * {@inheritDoc}
98       */
99      public TransactionIDFactory createTransactionIDFactory(String clusterUUID) {
100         client.waitUntilRejoinComplete();
101         return delegate.createTransactionIDFactory(clusterUUID);
102     }
103 
104     /***
105      * {@inheritDoc}
106      */
107     public WriteBehind createWriteBehind(Ehcache cache) {
108         client.waitUntilRejoinComplete();
109         return delegate.createWriteBehind(cache);
110     }
111 
112     /***
113      * {@inheritDoc}
114      */
115     public SoftLockFactory getOrCreateSoftLockFactory(String cacheName) {
116         client.waitUntilRejoinComplete();
117         return delegate.getOrCreateSoftLockFactory(cacheName);
118     }
119 
120     /***
121      * {@inheritDoc}
122      */
123     public void shutdown() {
124         delegate.shutdown();
125     }
126 
127 }