本文整理汇总了Java中org.apache.commons.lang3.concurrent.ConcurrentUtils类的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentUtils类的具体用法?Java ConcurrentUtils怎么用?Java ConcurrentUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConcurrentUtils类属于org.apache.commons.lang3.concurrent包,在下文中一共展示了ConcurrentUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入依赖的package包/类
@Override
public <T> Future<T> execute(final Controller controller, final BackgroundActionRegistry registry, final BackgroundAction<T> action) {
if(log.isDebugEnabled()) {
log.debug(String.format("Run action %s in background", action));
}
registry.add(action);
action.init();
// Start background task
final Callable<T> command = new BackgroundCallable<T>(action, controller, registry);
try {
final Future<T> task = concurrentExecutor.execute(command);
if(log.isInfoEnabled()) {
log.info(String.format("Scheduled background runnable %s for execution", action));
}
return task;
}
catch(RejectedExecutionException e) {
log.error(String.format("Error scheduling background task %s for execution. %s", action, e.getMessage()));
action.cleanup();
return ConcurrentUtils.constantFuture(null);
}
}
示例2: groupedThreadFactory
import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入依赖的package包/类
/**
* Returns thread factory for producing threads associated with the specified
* group name. The group name-space is hierarchical, based on slash-delimited
* name segments, e.g. {@code onos/intent}.
*
* @param groupName group name
* @return thread factory
*/
public static GroupedThreadFactory groupedThreadFactory(String groupName) {
GroupedThreadFactory factory = FACTORIES.get(groupName);
if (factory != null) {
return factory;
}
// Find the parent group or root the group hierarchy under default group.
int i = groupName.lastIndexOf(DELIMITER);
if (i > 0) {
String name = groupName.substring(0, i);
ThreadGroup parentGroup = groupedThreadFactory(name).threadGroup();
factory = new GroupedThreadFactory(new ThreadGroup(parentGroup, groupName));
} else {
factory = new GroupedThreadFactory(new ThreadGroup(groupName));
}
return ConcurrentUtils.putIfAbsent(FACTORIES, groupName, factory);
}
示例3: setUp
import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入依赖的package包/类
@Before
public void setUp() {
config = Configuration.buildFromConfig("config-mock.properties");
when(connectionStrategy.getHttpClient()).thenReturn(asyncHttpClient);
HttpResponse response = mock(HttpResponse.class);
Future<HttpResponse> future = ConcurrentUtils.constantFuture(response);
when(asyncHttpClient.execute(any(HttpUriRequest.class),any(FutureCallback.class))).thenReturn(future, null);
HttpEntity httpEntity = mock(HttpEntity.class);
when(response.getEntity()).thenReturn(httpEntity);
StatusLine statusLine = mock(StatusLine.class);
when(response.getStatusLine()).thenReturn(statusLine);
when(statusLine.getStatusCode()).thenReturn(200);
try {
InputStream inputStream = IOUtils.toInputStream(SERVER_RESPONSE_EXPECTED, "UTF-8");
when(httpEntity.getContent()).thenReturn(inputStream);
client = new LogInsightClient(config, connectionStrategy);
// client.connect(user, password);
assertEquals("Invalid session id!!",
"qyOLWEe7f/GjdM1WnczrCeQure97B/NpTbWTeqqYPBd1AYMf9cMNfQYqltITI4ffPMx822Sz9i/X47t8VwsDb0oGckclJUdn83cyIPk6WlsOpI4Yjw6WpurAnv9RhDsYSzKhAMzskzhTOJKfDHZjWR5v576WwtJA71wqI7igFrG91LG5c/3GfzMb68sUHF6hV+meYtGS4A1y/lUItvfkqTTAxBtTCZNoKrvCJZ4R+b6vuAAYoBNSWL7ycIy2LsALrVFxftAkA8n9DBAZYA9T5A==",
client.getSessionId());
} catch (Exception e) {
logger.error("Exception raised " + ExceptionUtils.getStackTrace(e));
}
}
示例4: groupedThreadFactory
import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入依赖的package包/类
/**
* Returns thread factory for producing threads associated with the specified
* group name. The group name-space is hierarchical, based on slash-delimited
* name segments,
*
* @param groupName group name
* @return thread factory
*/
public static AtriumGroupedThreadFactory groupedThreadFactory(String groupName) {
AtriumGroupedThreadFactory factory = FACTORIES.get(groupName);
if (factory != null) {
return factory;
}
// Find the parent group or root the group hierarchy under default group.
int i = groupName.lastIndexOf(DELIMITER);
if (i > 0) {
String name = groupName.substring(0, i);
ThreadGroup parentGroup = groupedThreadFactory(name).threadGroup();
factory = new AtriumGroupedThreadFactory(new ThreadGroup(parentGroup, groupName));
} else {
factory = new AtriumGroupedThreadFactory(new ThreadGroup(groupName));
}
return ConcurrentUtils.putIfAbsent(FACTORIES, groupName, factory);
}
示例5: getLogValue
import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入依赖的package包/类
/**
* Reads LogValue from LogMap.
* <p>
* It will use the cached value if it exist, if not it will
* get the value from distributed store.
*
* @param key log sequence number
* @return Future containing log value
*/
public Future<LogValue> getLogValue(final SeqNum key) {
try {
return cache.get(key, new Callable<Future<LogValue>>() {
@Override
public Future<LogValue> call() throws Exception {
return logMap.getAsync(key);
}
});
} catch (ExecutionException e) {
log.error("Reading from Log Map failed.", e);
// should never happen?
return ConcurrentUtils.constantFuture(null);
}
}
示例6: publishAddPortEvent
import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入依赖的package包/类
/**
* Publishes ADD Port Event.
*
* @param portData the port event to publish
*/
private void publishAddPortEvent(PortData portData) {
if (!registryService.hasControl(portData.getOriginDpid().value())) {
log.debug("Not the master for switch {}. Suppressed port add event {}.",
portData.getOriginDpid(), portData);
return;
}
// Publish the information
TopologyBatchOperation tbo = new TopologyBatchOperation();
TopologyEvent topologyEvent =
new TopologyEvent(portData, getOnosInstanceId());
tbo.appendAddOperation(topologyEvent);
publishTopologyOperations(tbo);
// Store the new Port Event in the local cache
ConcurrentMap<ByteBuffer, PortData> portDataEntries =
ConcurrentUtils.putIfAbsent(publishedPortDataEntries,
portData.getDpid(),
new ConcurrentHashMap<ByteBuffer, PortData>());
portDataEntries.put(portData.getIDasByteBuffer(), portData);
}
示例7: publishAddLinkEvent
import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入依赖的package包/类
/**
* Publishes ADD Link Event.
*
* @param linkData the link event to publish
*/
private void publishAddLinkEvent(LinkData linkData) {
if (!registryService.hasControl(linkData.getOriginDpid().value())) {
log.debug("Not the master for dst switch {}. Suppressed link add event {}.",
linkData.getOriginDpid(), linkData);
return;
}
// Publish the information
TopologyBatchOperation tbo = new TopologyBatchOperation();
TopologyEvent topologyEvent =
new TopologyEvent(linkData, getOnosInstanceId());
tbo.appendAddOperation(topologyEvent);
publishTopologyOperations(tbo);
// Store the new Link Event in the local cache
ConcurrentMap<ByteBuffer, LinkData> linkDataEntries =
ConcurrentUtils.putIfAbsent(publishedLinkDataEntries,
linkData.getDst().getDpid(),
new ConcurrentHashMap<ByteBuffer, LinkData>());
linkDataEntries.put(linkData.getIDasByteBuffer(), linkData);
}
示例8: run
import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入依赖的package包/类
public Future<Boolean> run(String...args) {
String[] argA = new String[2 + args.length];
argA[0] = DEFAULT_SHELL;
argA[1] = scriptFile;
for (int i = 0; i < args.length; i++) {
argA[2+i] = args[i];
}
ProcessBuilder scriptPB = new ProcessBuilder(argA);
scriptPB.redirectErrorStream(true);
try {
Process scriptProcess = scriptPB.start();
Future<Boolean> scriptStatus = TimerManager.get().submit( new TrackShell(scriptProcess) );
return scriptStatus;
} catch (IOException e) {
log.error("Error invoking script: " + scriptFile, e);
return ConcurrentUtils.constantFuture(false);
}
}
示例9: background
import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入依赖的package包/类
/**
* Will queue up the <code>BackgroundAction</code> to be run in a background thread
*
* @param action The runnable to execute in a secondary thread
*/
@Override
public <T> Future<T> background(final BackgroundAction<T> action) {
if(registry.contains(action)) {
log.warn(String.format("Skip duplicate background action %s found in registry", action));
return ConcurrentUtils.constantFuture(null);
}
return DefaultBackgroundExecutor.get().execute(this, registry, action);
}
示例10: getJsonObject
import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入依赖的package包/类
@Override
public Future<Response> getJsonObject(
SuccessCallback success,
HttpErrorCallback error,
FailureCallback failure,
String resourcePath
) {
LOG.info("Invoking test druid webservice: {}", this);
// Store the most recent query sent through
lastUrl = resourcePath;
// Invoke failure callback if we have a throwable to give it
if (throwable != null) {
failure.invoke(throwable);
return CompletedFuture.throwing(throwable);
}
try {
if (statusCode == 200) {
success.invoke(mapper.readTree(jsonResponse.call()));
} else {
error.invoke(statusCode, reasonPhrase, jsonResponse.call());
}
} catch (IOException e) {
failure.invoke(e);
return CompletedFuture.throwing(throwable);
}
return ConcurrentUtils.constantFuture(null);
}
示例11: saveAsync
import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> FutureObject<T> saveAsync(Object object) {
ObjectHolder objectHolder = new ObjectHolder(object);
setIdIfNecessary(objectHolder);
MockStore.put(objectHolder.getId(), object, tx());
Future<?> futureId = ConcurrentUtils.constantFuture(objectHolder.getId());
return new FutureObject<T>(r, (Future<IdRef<?>>) futureId, (T) object);
}
示例12: getLogMapManager
import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入依赖的package包/类
/**
* Gets the LogMapManager for given {@link SharedLogObjectID}.
* <p/>
* If listener was not registered, it will create and register a listener.
*
* @param oid {@link SharedLogObjectID}
* @return {@link LogMapManager}
*/
private LogMapManager getLogMapManager(final SharedLogObjectID oid) {
LogMapManager listener
= ConcurrentUtils.createIfAbsentUnchecked(listenerMap, oid,
new ConcurrentInitializer<LogMapManager>() {
@Override
public LogMapManager get() throws ConcurrentException {
IMap<SeqNum, LogValue> logMap = getLogMap(oid);
return new LogMapManager(oid, logMap);
}
});
return listener;
}
示例13: entryAdded
import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入依赖的package包/类
@Override
public void entryAdded(EntryEvent<SeqNum, LogValue> event) {
// Cache maintenance
cache.put(event.getKey(),
ConcurrentUtils.constantFuture(event.getValue()));
// TODO will need suppress mechanism once we have health check
if (lastLog.compareTo(event.getKey()) < 0) {
lastLog = event.getKey();
}
for (LogEventListener lsnr : listeners) {
lsnr.logAdded(event.getKey());
}
}
示例14: entryUpdated
import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入依赖的package包/类
@Override
public void entryUpdated(EntryEvent<SeqNum, LogValue> event) {
// Cache maintenance
cache.put(event.getKey(),
ConcurrentUtils.constantFuture(event.getValue()));
// only add will be notified to listeners
}
示例15: publishAddHostEvent
import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入依赖的package包/类
/**
* Publishes ADD Host Event.
*
* @param hostData the host event to publish
*/
private void publishAddHostEvent(HostData hostData) {
//
// NOTE: The implementation below assumes that there is just one
// attachment point stored in hostData. Currently, this assumption
// is true based on the existing implementation of the caller
// hostAdded().
//
if (!registryService.hasControl(hostData.getOriginDpid().value())) {
log.debug("Not the master for attachment switch {}. Suppressed host add event {}.",
hostData.getOriginDpid(), hostData);
return;
}
// Publish the information
TopologyBatchOperation tbo = new TopologyBatchOperation();
TopologyEvent topologyEvent =
new TopologyEvent(hostData, getOnosInstanceId());
tbo.appendAddOperation(topologyEvent);
publishTopologyOperations(tbo);
// Store the new Host Event in the local cache
ConcurrentMap<ByteBuffer, HostData> hostDataEntries =
ConcurrentUtils.putIfAbsent(publishedHostDataEntries,
hostData.getOriginDpid(),
new ConcurrentHashMap<ByteBuffer, HostData>());
hostDataEntries.put(hostData.getIDasByteBuffer(), hostData);
}