Beispiel #1
0
  @Override
  public void start() throws CacheLoaderException {
    final Marshaller marshaller;
    if (configuration.marshaller() != null) {
      marshaller =
          Util.getInstance(
              configuration.marshaller(), ctx.getCache().getCacheConfiguration().classLoader());
    } else if (configuration.hotRodWrapping()) {
      marshaller = new HotRodEntryMarshaller(ctx.getByteBufferFactory());
    } else if (configuration.rawValues()) {
      marshaller = new GenericJBossMarshaller();
    } else {
      marshaller = ctx.getMarshaller();
    }
    ConfigurationBuilder builder = buildRemoteConfiguration(configuration, marshaller);
    remoteCacheManager = new RemoteCacheManager(builder.build());

    if (configuration.remoteCacheName().equals(BasicCacheContainer.DEFAULT_CACHE_NAME))
      remoteCache = remoteCacheManager.getCache();
    else remoteCache = remoteCacheManager.getCache(configuration.remoteCacheName());
    if (configuration.rawValues() && iceFactory == null) {
      iceFactory =
          ctx.getCache()
              .getAdvancedCache()
              .getComponentRegistry()
              .getComponent(InternalEntryFactory.class);
    }
  }
Beispiel #2
0
 @Override
 public void init(InitializationContext ctx) {
   this.configuration = ctx.getConfiguration();
   this.emfRegistry =
       ctx.getCache()
           .getAdvancedCache()
           .getComponentRegistry()
           .getGlobalComponentRegistry()
           .getComponent(EntityManagerFactoryRegistry.class);
   this.marshallerEntryFactory = ctx.getMarshalledEntryFactory();
   this.marshaller = ctx.getMarshaller();
   this.timeService = ctx.getTimeService();
 }
Beispiel #3
0
  /** Rebuilds the in-memory index from file. */
  private void rebuildIndex() throws Exception {
    ByteBuffer buf = ByteBuffer.allocate(KEY_POS);
    for (; ; ) {
      // read FileEntry fields from file (size, keyLen etc.)
      buf.clear().limit(KEY_POS);
      channel.read(buf, filePos);
      // return if end of file is reached
      if (buf.remaining() > 0) return;
      buf.flip();

      // initialize FileEntry from buffer
      int entrySize = buf.getInt();
      int keyLen = buf.getInt();
      int dataLen = buf.getInt();
      int metadataLen = buf.getInt();
      long expiryTime = buf.getLong();
      FileEntry fe = new FileEntry(filePos, entrySize, keyLen, dataLen, metadataLen, expiryTime);

      // sanity check
      if (fe.size < KEY_POS + fe.keyLen + fe.dataLen + fe.metadataLen) {
        throw log.errorReadingFileStore(file.getPath(), filePos);
      }

      // update file pointer
      filePos += fe.size;

      // check if the entry is used or free
      if (fe.keyLen > 0) {
        // load the key from file
        if (buf.capacity() < fe.keyLen) buf = ByteBuffer.allocate(fe.keyLen);

        buf.clear().limit(fe.keyLen);
        channel.read(buf, fe.offset + KEY_POS);

        // deserialize key and add to entries map
        // Marshaller should allow for provided type return for safety
        K key = (K) ctx.getMarshaller().objectFromByteBuffer(buf.array(), 0, fe.keyLen);
        entries.put(key, fe);
      } else {
        // add to free list
        freeList.add(fe);
      }
    }
  }