@Override public void close() { for (R2Store store : this.rawStoreList) { store.close(); } // shutdown the transportclient in the case when no r2store is created if (this.transportClient != null) { final FutureCallback<None> clientShutdownCallback = new FutureCallback<None>(); this.transportClient.shutdown(clientShutdownCallback); try { clientShutdownCallback.get(); } catch (InterruptedException e) { logger.error("Interrupted while shutting down the TransportClient: " + e.getMessage(), e); } catch (ExecutionException e) { logger.error( "Execution exception occurred while shutting down the TransportClient: " + e.getMessage(), e); } } final FutureCallback<None> factoryShutdownCallback = new FutureCallback<None>(); this._clientFactory.shutdown(factoryShutdownCallback); try { factoryShutdownCallback.get(); } catch (InterruptedException e) { logger.error("Interrupted while shutting down the HttpClientFactory: " + e.getMessage(), e); } catch (ExecutionException e) { logger.error( "Execution exception occurred while shutting down the HttpClientFactory: " + e.getMessage(), e); } }
@Override public <K, V, T> Store<K, V, T> getRawStore( String storeName, InconsistencyResolver<Versioned<V>> resolver) { Store<K, V, T> clientStore = null; // The lowest layer : Transporting request to coordinator R2Store r2store = null; this.d2Client = restClientFactoryConfig.getD2Client(); if (this.d2Client == null) { r2store = new R2Store( storeName, this.config.getHttpBootstrapURL(), this.transportClient, this.config); } else { r2store = new R2Store(storeName, this.config.getHttpBootstrapURL(), this.d2Client, this.config); } this.rawStoreList.add(r2store); // bootstrap from the coordinator and obtain all the serialization // information. String serializerInfoXml = r2store.getSerializerInfoXml(); SerializerDefinition keySerializerDefinition = RestUtils.parseKeySerializerDefinition(serializerInfoXml); SerializerDefinition valueSerializerDefinition = RestUtils.parseValueSerializerDefinition(serializerInfoXml); synchronized (this) { keySerializerMap.put(storeName, keySerializerDefinition); valueSerializerMap.put(storeName, valueSerializerDefinition); } if (logger.isDebugEnabled()) { logger.debug( "Bootstrapping for " + storeName + ": Key serializer " + keySerializerDefinition); logger.debug( "Bootstrapping for " + storeName + ": Value serializer " + valueSerializerDefinition); } // Start building the stack.. // First, the transport layer Store<ByteArray, byte[], byte[]> store = r2store; // TODO: Add jmxId / some unique identifier to the Mbean name if (this.config.isEnableJmx()) { StatTrackingStore statStore = new StatTrackingStore(store, this.stats); store = statStore; JmxUtils.registerMbean( new StoreStatsJmx(statStore.getStats()), JmxUtils.createObjectName(JmxUtils.getPackageName(store.getClass()), store.getName())); } // Add compression layer if (keySerializerDefinition.hasCompression() || valueSerializerDefinition.hasCompression()) { store = new CompressingStore( store, new CompressionStrategyFactory().get(keySerializerDefinition.getCompression()), new CompressionStrategyFactory().get(valueSerializerDefinition.getCompression())); } // Add Serialization layer Serializer<K> keySerializer = (Serializer<K>) serializerFactory.getSerializer(keySerializerDefinition); Serializer<V> valueSerializer = (Serializer<V>) serializerFactory.getSerializer(valueSerializerDefinition); clientStore = SerializingStore.wrap(store, keySerializer, valueSerializer, null); // Add inconsistency Resolving layer InconsistencyResolver<Versioned<V>> secondaryResolver = resolver == null ? new TimeBasedInconsistencyResolver<V>() : resolver; clientStore = new InconsistencyResolvingStore<K, V, T>( clientStore, new ChainedResolver<Versioned<V>>( new VectorClockInconsistencyResolver<V>(), secondaryResolver)); return clientStore; }