本文整理汇总了Java中net.spy.memcached.ConnectionFactory类的典型用法代码示例。如果您正苦于以下问题:Java ConnectionFactory类的具体用法?Java ConnectionFactory怎么用?Java ConnectionFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionFactory类属于net.spy.memcached包,在下文中一共展示了ConnectionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: memcachedClient
import net.spy.memcached.ConnectionFactory; //导入依赖的package包/类
@Bean
public MemcachedClient memcachedClient(ObjectProvider<ConnectionFactory> connection) throws IOException {
final List<InetSocketAddress> addresses = new ArrayList<>();
final String servers = environment.getProperty("memcached.servers");
if (StringUtils.isEmpty(servers)) {
addresses.add(new InetSocketAddress(LOCALHOST, DEFAULT_PORT));
} else {
for (final String server : servers.split(",")) {
final int colon = server.indexOf(":");
if (colon == -1) {
addresses.add(new InetSocketAddress(server, DEFAULT_PORT));
} else {
final int port = Integer.parseInt(server.substring(colon + 1));
addresses.add(new InetSocketAddress(server.substring(0, colon), port));
}
}
}
ConnectionFactory con = connection.getIfUnique();
return con == null
? new MemcachedClient(addresses)
: new MemcachedClient(con, addresses);
}
示例2: FrontCacheMemcachedClient
import net.spy.memcached.ConnectionFactory; //导入依赖的package包/类
/**
* Create the memcached client and the front cache.
*
* @param cf the connection factory to configure connections for this client
* @param addrs the socket addresses for the memcached servers
* @throws IOException if connections cannot be established
*/
public FrontCacheMemcachedClient(ConnectionFactory cf,
List<InetSocketAddress> addrs) throws IOException {
super(cf, addrs);
if (cf.getMaxFrontCacheElements() > 0) {
String cacheName = cf.getFrontCacheName();
int maxElements = cf.getMaxFrontCacheElements();
int timeToLiveSeconds = cf.getFrontCacheExpireTime();
boolean copyOnRead = cf.getFrontCacheCopyOnRead();
boolean copyOnWrite = cf.getFrontCacheCopyOnWrite();
// TODO add an additional option
// int timeToIdleSeconds = timeToLiveSeconds;
localCacheManager = new LocalCacheManager(cacheName, maxElements,
timeToLiveSeconds, copyOnRead, copyOnWrite);
}
}
示例3: EVCacheNodeImpl
import net.spy.memcached.ConnectionFactory; //导入依赖的package包/类
public EVCacheNodeImpl(SocketAddress sa, SocketChannel c, int bufSize, BlockingQueue<Operation> rq,
BlockingQueue<Operation> wq, BlockingQueue<Operation> iq,
long opQueueMaxBlockTimeMillis, boolean waitForAuth, long dt, long at, ConnectionFactory fa, String appName,
int id, ServerGroup serverGroup, long stTime) {
super(sa, c, bufSize, rq, wq, iq, Long.valueOf(opQueueMaxBlockTimeMillis), waitForAuth, dt, at, fa);
this.id = id;
this._appName = appName;
this._serverGroup = serverGroup;
setConnectTime(stTime);
this.readQ = rq;
this.inputQueue = iq;
this.sendMetrics = EVCacheConfig.getInstance().getDynamicBooleanProperty("EVCacheNodeImpl." + appName + ".sendMetrics", false);
this.tags = BasicTagList.of("ServerGroup", _serverGroup.getName(), "APP", appName, "Id", String.valueOf(id), EVCacheMetricsFactory.OWNER.getKey(), EVCacheMetricsFactory.OWNER.getValue());
this.hostName = ((InetSocketAddress) getSocketAddress()).getHostName();
this.metricPrefix = "EVCacheNode";
this.baseConfig = MonitorConfig.builder(metricPrefix).build();
baseTags = BasicTagList.concat(tags, BasicTagList.of("HOST", hostName));
setupMonitoring();
}
示例4: assertMemcachedClient
import net.spy.memcached.ConnectionFactory; //导入依赖的package包/类
private void assertMemcachedClient(MemcachedClient memcachedClient, ClientMode clientMode, InetSocketAddress... servers) {
List<NodeEndPoint> nodeEndPoints = (List<NodeEndPoint>) memcachedClient.getAllNodeEndPoints();
assertThat(nodeEndPoints)
.as("The number of memcached node endpoints should match server list size")
.hasSize(servers.length);
ConnectionFactory cf = (ConnectionFactory) ReflectionTestUtils.getField(memcachedClient, "connFactory");
for (int i = 0; i < nodeEndPoints.size(); i++) {
NodeEndPoint nodeEndPoint = nodeEndPoints.get(i);
InetSocketAddress server = servers[i];
String host = server.getHostString();
int port = server.getPort();
assertThat(host.matches("\\w+") ? nodeEndPoint.getHostName() : nodeEndPoint.getIpAddress())
.as("Memcached node endpoint host is incorrect")
.isEqualTo(host);
assertThat(nodeEndPoint.getPort())
.as("Memcached node endpoint port is incorrect")
.isEqualTo(port);
}
assertThat(cf.getClientMode())
.as("Memcached node endpoint mode is incorrect")
.isEqualTo(clientMode);
}
示例5: getCouchBaseConnection
import net.spy.memcached.ConnectionFactory; //导入依赖的package包/类
@Override
protected CouchbaseClient getCouchBaseConnection(
CouchbaseConnectionFactoryBuilder connectionFactoryBuilder)
throws IOException {
ConnectionFactory factory = connectionFactoryBuilder.build();
Assert.assertEquals(factory.getOperationTimeout(), 10223);
assertEquals(factory.getOpQueueMaxBlockTime(), 10223);
return Mockito.mock(CouchbaseClient.class);
}
示例6: setupBeforeClass
import net.spy.memcached.ConnectionFactory; //导入依赖的package包/类
@BeforeClass
public static void setupBeforeClass() throws IOException {
final ConnectionFactory cf = new ConnectionFactoryBuilder()
.setProtocol(ConnectionFactoryBuilder.Protocol.TEXT)
.setTranscoder(new WhalinTranscoder())
.setOpTimeout(1000)
.build();
spyClient = new MemcachedClient(cf, Collections.singletonList(new InetSocketAddress("localhost", MEMCACHED_PORT)));
}
示例7: get
import net.spy.memcached.ConnectionFactory; //导入依赖的package包/类
@Override
public MemcachedClient get() {
client = throwingSupplier(() -> {
ConnectionFactory connectionFactory = builder.build();
this.builder = null;
return new MemcachedClient(connectionFactory, servers);
}).get();
return client;
}
示例8: ApiMemcached
import net.spy.memcached.ConnectionFactory; //导入依赖的package包/类
public ApiMemcached() {
AppConstants ac = AppConstants.getInstance();
String address = ac.getProperty("etag.cache.server", "localhost:11211");
String username = ac.getProperty("etag.cache.username", "");
String password = ac.getProperty("etag.cache.password", "");
int timeout = ac.getInt("etag.cache.timeout", 10);
List<InetSocketAddress> addresses = AddrUtil.getAddresses(address);
ConnectionFactoryBuilder connectionFactoryBuilder = new ConnectionFactoryBuilder()
.setProtocol(Protocol.BINARY)
.setOpTimeout(timeout)
.setInitialObservers(Collections.singleton(obs));
if(addresses.size() > 1)
connectionFactoryBuilder.setFailureMode(FailureMode.Redistribute);
else
connectionFactoryBuilder.setFailureMode(FailureMode.Retry);
if(!username.isEmpty())
connectionFactoryBuilder.setAuthDescriptor(AuthDescriptor.typical(username, password));
ConnectionFactory cf = connectionFactoryBuilder.build();
try {
client = new MemcachedClient(cf, addresses);
//Fetching a none-existing key to test the connection
Future<Object> future = client.asyncGet("test-connection");
future.get(timeout, TimeUnit.MILLISECONDS);
} catch (Exception e) {
ConfigurationWarnings.getInstance().add(log, "Unable to connect to one or more memcached servers.", null, true);
}
}
示例9: convert
import net.spy.memcached.ConnectionFactory; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected ConnectionFactory convert(String property) throws Exception {
Class<?> clazz = Class.forName(property);
if (!ConnectionFactory.class.isAssignableFrom(clazz)) {
throw new IllegalArgumentException(
"Class '" + clazz.getName() + "' is not a valid '" + ConnectionFactory.class.getName() + "' implementation");
}
return (ConnectionFactory) clazz.newInstance();
}
示例10: getConnectionFactory
import net.spy.memcached.ConnectionFactory; //导入依赖的package包/类
public ConnectionFactory getConnectionFactory(String appName, int id, ServerGroup serverGroup, EVCacheClientPoolManager poolManager) {
final int maxQueueSize = EVCacheConfig.getInstance().getDynamicIntProperty(appName + ".max.queue.length", 16384).get();
final DynamicIntProperty operationTimeout = EVCacheConfig.getInstance().getDynamicIntProperty(appName + ".operation.timeout", 2500);
final int opQueueMaxBlockTime = EVCacheConfig.getInstance().getDynamicIntProperty(appName + ".operation.QueueMaxBlockTime", 10).get();
return new BaseConnectionFactory(appName, maxQueueSize, operationTimeout, opQueueMaxBlockTime, id, serverGroup, poolManager);
}
示例11: connectionFactory
import net.spy.memcached.ConnectionFactory; //导入依赖的package包/类
private ConnectionFactory connectionFactory() {
ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder();
builder.setOpTimeout(timeout);
return builder.build();
}
示例12: MockMemcachedClient
import net.spy.memcached.ConnectionFactory; //导入依赖的package包/类
public MockMemcachedClient(ConnectionFactory cf,
List<InetSocketAddress> addrs) throws IOException {
super(cf, addrs);
}
示例13: createClient
import net.spy.memcached.ConnectionFactory; //导入依赖的package包/类
static protected void createClient() throws IOException {
ConnectionFactory connectionFactory = new ConnectionFactoryBuilder().setOpTimeout(TIMEOUT).setProtocol(ConnectionFactoryBuilder.Protocol.BINARY).build();
client = new MemcachedClient(connectionFactory, Arrays.asList(new InetSocketAddress("localhost", getPort())));
}
示例14: getConnectionFactory
import net.spy.memcached.ConnectionFactory; //导入依赖的package包/类
/**
* @return the connectionFactory
*/
public ConnectionFactory getConnectionFactory() {
return connectionFactory;
}
示例15: setConnectionFactory
import net.spy.memcached.ConnectionFactory; //导入依赖的package包/类
/**
* @param connectionFactory the connectionFactory to set
*/
public void setConnectionFactory(ConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}