javax.cache.configuration.Factory.create()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(106)

本文整理了Java中javax.cache.configuration.Factory.create()方法的一些代码示例,展示了Factory.create()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Factory.create()方法的具体详情如下:
包路径:javax.cache.configuration.Factory
类名称:Factory
方法名:create

Factory.create介绍

[英]Constructs and returns a fully configured instance of T.
[中]构造并返回完全配置的T实例。

代码示例

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override protected IgniteClosure<CacheEntryEvent<? extends K, ? extends V>, ?> getTransformer() {
  if (rmtTrans == null && rmtTransFactory != null)
    rmtTrans = rmtTransFactory.create();
  return rmtTrans;
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public CacheStore<K, V> create() {
  CacheLoader<K, V> ldr = ldrFactory == null ? null : ldrFactory.create();
  CacheWriter<K, V> writer = writerFactory == null ? null : writerFactory.create();
  return new GridCacheLoaderWriterStore<>(ldr, writer);
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
  @Override public SSLSocketFactory create() {
    return getTestSslContextFactory().create().getSocketFactory();
  }
}

代码示例来源:origin: ben-manes/caffeine

Builder(String cacheName, CaffeineConfiguration<K, V> config) {
 this.config = config;
 this.cacheName = cacheName;
 this.caffeine = Caffeine.newBuilder();
 this.statistics = new JCacheStatisticsMXBean();
 this.ticker = config.getTickerFactory().create();
 this.executor = config.getExecutorFactory().create();
 this.expiryPolicy = config.getExpiryPolicyFactory().create();
 this.dispatcher = new EventDispatcher<>(executor);
 caffeine.executor(executor);
 config.getCacheEntryListenerConfigurations().forEach(dispatcher::register);
}

代码示例来源:origin: ben-manes/caffeine

/** @return a writer created by the configured factory or null if not set. */
public @Nullable CacheWriter<K , V> getCacheWriter() {
 if (hasCacheWriter()) {
  @SuppressWarnings("unchecked")
  CacheWriter<K , V> writer = (CacheWriter<K, V>) getCacheWriterFactory().create();
  return writer;
 }
 return null;
}

代码示例来源:origin: ben-manes/caffeine

static void checkStoreByValue(CaffeineConfiguration<?, ?> config) {
 assertThat(config.isStoreByValue(), is(true));
 assertThat(config.getCopierFactory().create(),
   instanceOf(JavaSerializationCopier.class));
}

代码示例来源:origin: ben-manes/caffeine

static void checkListener(CaffeineConfiguration<?, ?> config) {
 CacheEntryListenerConfiguration<?, ?> listener = Iterables.getOnlyElement(
   config.getCacheEntryListenerConfigurations());
 assertThat(listener.getCacheEntryListenerFactory().create(),
   instanceOf(TestCacheEntryListener.class));
 assertThat(listener.getCacheEntryEventFilterFactory().create(),
   instanceOf(TestCacheEntryEventFilter.class));
 assertThat(listener.isSynchronous(), is(true));
 assertThat(listener.isOldValueRequired(), is(true));
}

代码示例来源:origin: ben-manes/caffeine

static void checkLazyExpiration(CaffeineConfiguration<?, ?> config) {
 ExpiryPolicy expiry = config.getExpiryPolicyFactory().create();
 assertThat(expiry.getExpiryForCreation(), is(Duration.ONE_MINUTE));
 assertThat(expiry.getExpiryForUpdate(), is(Duration.FIVE_MINUTES));
 assertThat(expiry.getExpiryForAccess(), is(Duration.TEN_MINUTES));
}

代码示例来源:origin: ben-manes/caffeine

/** Creates a cache that reads through on a cache miss. */
private CacheProxy<K, V> newLoadingCacheProxy() {
 CacheLoader<K, V> cacheLoader = config.getCacheLoaderFactory().create();
 JCacheLoaderAdapter<K, V> adapter = new JCacheLoaderAdapter<>(
   cacheLoader, dispatcher, expiryPolicy, ticker, statistics);
 CacheProxy<K, V> cache = new LoadingCacheProxy<>(cacheName, executor, cacheManager, config,
   caffeine.build(adapter), dispatcher, cacheLoader, expiryPolicy, ticker, statistics);
 adapter.setCache(cache);
 return cache;
}

代码示例来源:origin: ben-manes/caffeine

static void checkTestCache(CaffeineConfiguration<?, ?> config) {
 checkStoreByValue(config);
 checkListener(config);
 assertThat(config.getKeyType(), is(Object.class));
 assertThat(config.getValueType(), is(Object.class));
 assertThat(config.getCacheLoaderFactory().create(),
   instanceOf(TestCacheLoader.class));
 assertThat(config.getCacheWriter(), instanceOf(TestCacheWriter.class));
 assertThat(config.isStatisticsEnabled(), is(true));
 assertThat(config.isManagementEnabled(), is(true));
 checkSize(config);
 checkRefresh(config);
 checkLazyExpiration(config);
 checkEagerExpiration(config);
}

代码示例来源:origin: apache/ignite

@Override public void test(Factory factory, Ignite ignite) throws Exception {
    Collection<EchoCallable> jobs = new ArrayList<>(MAX_JOB_COUNT);
    for (int i = 0; i < MAX_JOB_COUNT; ++i) {
      EchoCallable job = (EchoCallable)factory.create();
      job.setArg(value(i - 1));
      jobs.add(job);
    }
    Collection<Object> results = ignite.compute().call(jobs);
    checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
    assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
  }
});

代码示例来源:origin: apache/ignite

@Override public void test(Factory factory, Ignite ignite) throws Exception {
    Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT);
    for (int i = 0; i < MAX_JOB_COUNT; ++i) {
      EchoCallable job = (EchoCallable)factory.create();
      job.setArg(value(i - 1));
      results.add(ignite.compute().call(job));
    }
    checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass());
    assertCollectionsEquals("Results value mismatch", createGoldenResults(), results);
  }
});

代码示例来源:origin: redisson/redisson

public JCache(JCacheManager cacheManager, Redisson redisson, String name, JCacheConfiguration<K, V> config, boolean hasOwnRedisson) {
  super(redisson.getConfig().getCodec(), redisson.getCommandExecutor(), name);
  
  this.hasOwnRedisson = hasOwnRedisson;
  this.redisson = redisson;
  
  Factory<CacheLoader<K, V>> cacheLoaderFactory = config.getCacheLoaderFactory();
  if (cacheLoaderFactory != null) {
    cacheLoader = cacheLoaderFactory.create();
  }
  Factory<CacheWriter<? super K, ? super V>> cacheWriterFactory = config.getCacheWriterFactory();
  if (config.getCacheWriterFactory() != null) {
    cacheWriter = (CacheWriter<K, V>) cacheWriterFactory.create();
  }
  
  this.cacheManager = cacheManager;
  this.config = config;
  
  redisson.getEvictionScheduler().scheduleJCache(getName(), getTimeoutSetName(), getExpiredChannelName());
  
  for (CacheEntryListenerConfiguration<K, V> listenerConfig : config.getCacheEntryListenerConfigurations()) {
    registerCacheEntryListener(listenerConfig, false);
  }
}

代码示例来源:origin: redisson/redisson

public JCache(JCacheManager cacheManager, Redisson redisson, String name, JCacheConfiguration<K, V> config, boolean hasOwnRedisson) {
  super(redisson.getConfig().getCodec(), redisson.getCommandExecutor(), name);
  
  this.hasOwnRedisson = hasOwnRedisson;
  this.redisson = redisson;
  
  Factory<CacheLoader<K, V>> cacheLoaderFactory = config.getCacheLoaderFactory();
  if (cacheLoaderFactory != null) {
    cacheLoader = cacheLoaderFactory.create();
  }
  Factory<CacheWriter<? super K, ? super V>> cacheWriterFactory = config.getCacheWriterFactory();
  if (config.getCacheWriterFactory() != null) {
    cacheWriter = (CacheWriter<K, V>) cacheWriterFactory.create();
  }
  
  this.cacheManager = cacheManager;
  this.config = config;
  
  redisson.getEvictionScheduler().scheduleJCache(getName(), getTimeoutSetName(), getExpiredChannelName());
  
  for (CacheEntryListenerConfiguration<K, V> listenerConfig : config.getCacheEntryListenerConfigurations()) {
    registerCacheEntryListener(listenerConfig, false);
  }
}

代码示例来源:origin: apache/ignite

@Override public void test(Factory factory, Ignite ignite) throws Exception {
    Collection<EchoCallable> jobs = new ArrayList<>(MAX_JOB_COUNT);
    for (int i = 0; i < MAX_JOB_COUNT; ++i) {
      EchoCallable job = (EchoCallable)factory.create();
      job.setArg(value(i - 1));
      jobs.add(job);
    }
    IgniteFuture<Collection<Object>> fut = ignite.compute().callAsync(jobs);
    checkResultsClassCount(MAX_JOB_COUNT - 1, fut.get(), value(0).getClass());
    assertCollectionsEquals("Results value mismatch", createGoldenResults(), fut.get());
  }
});

代码示例来源:origin: apache/ignite

@Override public void test(Factory factory, Ignite ignite) throws Exception {
    ignite.getOrCreateCache("test0");
    ignite.getOrCreateCache("test1");
    final IgniteCompute comp = ignite.compute();
    for (int i = 0; i < MAX_JOB_COUNT; ++i) {
      IgniteRunnable job = (IgniteRunnable)factory.create();
      IgniteFuture<Void> fut = comp.affinityRunAsync(Arrays.asList("test0", "test1"), 0, job);
      fut.get();
    }
  }
});

代码示例来源:origin: apache/ignite

@Override public void test(Factory factory, Ignite ignite) throws Exception {
    ignite.getOrCreateCache("test0");
    ignite.getOrCreateCache("test1");
    final IgniteCompute comp = ignite.compute();
    for (int i = 0; i < MAX_JOB_COUNT; ++i) {
      IgniteRunnable job = (IgniteRunnable)factory.create();
      IgniteFuture<Void> fut = comp.affinityRunAsync(Arrays.asList("test0", "test1"), key(0), job);
      fut.get();
    }
  }
});

代码示例来源:origin: redisson/redisson

public JCacheConfiguration(Configuration<K, V> configuration) {
  if (configuration != null) {
    if (configuration instanceof RedissonConfiguration) {
      configuration = ((RedissonConfiguration<K, V>)configuration).getJcacheConfig();
    }
    
    if (configuration instanceof CompleteConfiguration) {
      delegate = new MutableConfiguration<K, V>((CompleteConfiguration<K, V>) configuration);
    } else {
      delegate = new MutableConfiguration<K, V>();
      delegate.setStoreByValue(configuration.isStoreByValue());
      delegate.setTypes(configuration.getKeyType(), configuration.getValueType());
    }
  } else {
    delegate = new MutableConfiguration<K, V>();
  }
  
  this.expiryPolicy = delegate.getExpiryPolicyFactory().create();
}

代码示例来源:origin: redisson/redisson

public JCacheConfiguration(Configuration<K, V> configuration) {
  if (configuration != null) {
    if (configuration instanceof RedissonConfiguration) {
      configuration = ((RedissonConfiguration<K, V>)configuration).getJcacheConfig();
    }
    
    if (configuration instanceof CompleteConfiguration) {
      delegate = new MutableConfiguration<K, V>((CompleteConfiguration<K, V>) configuration);
    } else {
      delegate = new MutableConfiguration<K, V>();
      delegate.setStoreByValue(configuration.isStoreByValue());
      delegate.setTypes(configuration.getKeyType(), configuration.getValueType());
    }
  } else {
    delegate = new MutableConfiguration<K, V>();
  }
  
  this.expiryPolicy = delegate.getExpiryPolicyFactory().create();
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception if failed.
 */
@Test
public void testWithExpiryPolicyUnsupported() throws Exception {
  checkOperationUnsupported("withExpiryPolicy", m("withExpiryPolicy"), t(ExpiryPolicy.class),
    EternalExpiryPolicy.factoryOf().create());
}

相关文章

Factory类方法