Exemplo n.º 1
0
 @Override
 public <K, V> ConcurrentMap<K, V> createConcurrentParallelMap(
     int initialCapacity, int concurrencyLevel) {
   // by the time we baseline on JDK8 this code will be either dropped or adjusted,
   // for now we need to use ConcurrentParallelHashMapV8
   return new ConcurrentParallelHashMapV8<K, V>(
       initialCapacity, AnyEquivalence.<K>getInstance(), AnyEquivalence.<V>getInstance());
 }
Exemplo n.º 2
0
 public CompletedTransactionsInfo() {
   nodeMaxPrunedTxIds =
       new EquivalentConcurrentHashMapV8<>(
           AnyEquivalence.getInstance(), AnyEquivalence.getInstance());
   completedTransactions =
       new EquivalentConcurrentHashMapV8<>(
           AnyEquivalence.getInstance(), AnyEquivalence.getInstance());
   globalMaxPrunedTxId = -1;
 }
Exemplo n.º 3
0
 @Override
 public <K, V> ConcurrentMap<K, V> createConcurrentMap(
     int initialCapacity, int concurrencyLevel) {
   return new EquivalentConcurrentHashMapV8<K, V>(
       initialCapacity,
       0.75f,
       concurrencyLevel,
       AnyEquivalence.<K>getInstance(),
       AnyEquivalence.<V>getInstance());
 }
  @Override
  protected void createCacheManagers() throws Throwable {
    // todo [anistor] initializing the server-side context in this way is a hack. normally this
    // should use the protobuf metadata registry
    MarshallerRegistration.registerMarshallers(
        SerializationContextHolder.getSerializationContext());

    // initialize client-side serialization context
    MarshallerRegistration.registerMarshallers(ProtoStreamMarshaller.getSerializationContext());

    ConfigurationBuilder builder =
        hotRodCacheConfiguration(getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, false));
    builder
        .transaction()
        .indexing()
        .enable()
        .indexLocalOnly(false)
        .addProperty(
            "default.directory_provider", "ram") // todo test with  "infinispan" provider too
        .addProperty("lucene_version", "LUCENE_CURRENT");

    builder.dataContainer().valueEquivalence(AnyEquivalence.getInstance()); // TODO [anistor] hacks!

    createHotRodServers(2, builder);
  }
Exemplo n.º 5
0
 @BeforeMethod
 public void setUp() {
   n = new CacheNotifierImpl();
   mockCache = mock(Cache.class, RETURNS_DEEP_STUBS);
   Configuration config = mock(Configuration.class, RETURNS_DEEP_STUBS);
   when(mockCache.getAdvancedCache().getStatus()).thenReturn(ComponentStatus.INITIALIZING);
   Answer answer =
       new Answer<Object>() {
         @Override
         public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
           return Mockito.mock((Class) invocationOnMock.getArguments()[0]);
         }
       };
   when(mockCache.getAdvancedCache().getComponentRegistry().getComponent(any(Class.class)))
       .then(answer);
   when(mockCache
           .getAdvancedCache()
           .getComponentRegistry()
           .getComponent(any(Class.class), anyString()))
       .then(answer);
   n.injectDependencies(mockCache, cdl, null, config);
   cl = new PrimaryOwnerCacheListener();
   n.start();
   n.addListener(cl);
   ctx = new NonTxInvocationContext(AnyEquivalence.getInstance());
 }
Exemplo n.º 6
0
  private <Key> Map<Key, FileEntry> newEntryMap() {
    // only use LinkedHashMap (LRU) for entries when cache store is bounded
    final Map<Key, FileEntry> entryMap;
    Equivalence<Object> keyEq =
        ctx.getCache().getCacheConfiguration().dataContainer().keyEquivalence();
    if (configuration.maxEntries() > 0)
      entryMap = CollectionFactory.makeLinkedMap(16, 0.75f, true, null, null);
    else entryMap = CollectionFactory.makeMap(keyEq, AnyEquivalence.<FileEntry>getInstance());

    return Collections.synchronizedMap(entryMap);
  }
Exemplo n.º 7
0
 @Override
 public <K, V> ConcurrentMap<K, V> createConcurrentMap() {
   return new EquivalentConcurrentHashMapV8<K, V>(
       AnyEquivalence.<K>getInstance(), AnyEquivalence.<V>getInstance());
 }
Exemplo n.º 8
0
 private static <T> boolean requiresEquivalent(Equivalence<T> typeEq) {
   return typeEq != AnyEquivalence.getInstance();
 }
Exemplo n.º 9
0
 private static <K, V> boolean requiresEquivalent(Equivalence<K> keyEq, Equivalence<V> valueEq) {
   AnyEquivalence<Object> instance = AnyEquivalence.getInstance();
   return keyEq != instance || valueEq != instance;
 }
Exemplo n.º 10
0
 public CommitManager(Equivalence<Object> keyEq) {
   tracker = new EquivalentConcurrentHashMapV8<>(keyEq, AnyEquivalence.getInstance());
 }
 public LocalTxInvocationContext(Equivalence<Object> keyEq) {
   emptyEntryMap = CollectionFactory.makeMap(0, keyEq, AnyEquivalence.<CacheEntry>getInstance());
 }
Exemplo n.º 12
0
  @Start(priority = 9) // Start before cache loader manager
  @SuppressWarnings("unused")
  public void start() {
    final int concurrencyLevel = configuration.locking().concurrencyLevel();
    // use the IdentityEquivalence because some Transaction implementation does not have a stable
    // hash code function
    // and it can cause some leaks in the concurrent map.
    localTransactions =
        CollectionFactory.makeConcurrentMap(
            concurrencyLevel,
            0.75f,
            concurrencyLevel,
            new IdentityEquivalence<Transaction>(),
            AnyEquivalence.getInstance());
    globalToLocalTransactions =
        CollectionFactory.makeConcurrentMap(concurrencyLevel, 0.75f, concurrencyLevel);

    boolean transactional = configuration.transaction().transactionMode().isTransactional();
    if (clustered && transactional) {
      minTopologyRecalculationLock = new ReentrantLock();
      remoteTransactions =
          CollectionFactory.makeConcurrentMap(concurrencyLevel, 0.75f, concurrencyLevel);

      ThreadFactory tf =
          new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
              String address =
                  rpcManager != null ? rpcManager.getTransport().getAddress().toString() : "local";
              Thread th = new Thread(r, "TxCleanupService," + cacheName + "," + address);
              th.setDaemon(true);
              return th;
            }
          };
      executorService = Executors.newSingleThreadScheduledExecutor(tf);

      notifier.addListener(this);
      cacheManagerNotifier.addListener(this);

      boolean totalOrder = configuration.transaction().transactionProtocol().isTotalOrder();
      if (!totalOrder) {
        completedTransactionsInfo = new CompletedTransactionsInfo();

        // Periodically run a task to cleanup the transaction table of completed transactions.
        long interval = configuration.transaction().reaperWakeUpInterval();
        executorService.scheduleAtFixedRate(
            new Runnable() {
              @Override
              public void run() {
                completedTransactionsInfo.cleanupCompletedTransactions();
              }
            },
            interval,
            interval,
            TimeUnit.MILLISECONDS);

        executorService.scheduleAtFixedRate(
            new Runnable() {
              @Override
              public void run() {
                cleanupTimedOutTransactions();
              }
            },
            interval,
            interval,
            TimeUnit.MILLISECONDS);
      }
    }
  }