本文整理汇总了Java中org.apache.curator.utils.ThreadUtils类的典型用法代码示例。如果您正苦于以下问题:Java ThreadUtils类的具体用法?Java ThreadUtils怎么用?Java ThreadUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ThreadUtils类属于org.apache.curator.utils包,在下文中一共展示了ThreadUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeInstance
import org.apache.curator.utils.ThreadUtils; //导入依赖的package包/类
static<T> ObjectNode writeInstance(ObjectMapper mapper, ServiceInstance<T> instance, DiscoveryContext<T> context)
{
ObjectNode node = mapper.createObjectNode();
node.put("name", instance.getName());
node.put("id", instance.getId());
node.put("address", instance.getAddress());
putInteger(node, "port", instance.getPort());
putInteger(node, "sslPort", instance.getSslPort());
node.put("registrationTimeUTC", instance.getRegistrationTimeUTC());
node.put("serviceType", instance.getServiceType().name());
try
{
context.marshallJson(node, "payload", instance.getPayload());
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
throw new WebApplicationException(e);
}
return node;
}
示例2: readFrom
import org.apache.curator.utils.ThreadUtils; //导入依赖的package包/类
@Override
public ServiceInstances<T> readFrom(Class<ServiceInstances<T>> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException
{
try
{
List<ServiceInstance<T>> instances = Lists.newArrayList();
ObjectMapper mapper = new ObjectMapper();
JsonNode tree = mapper.reader().readTree(entityStream);
for ( int i = 0; i < tree.size(); ++i )
{
JsonNode node = tree.get(i);
ServiceInstance<T> instance = JsonServiceInstanceMarshaller.readInstance(node, context);
instances.add(instance);
}
return new ServiceInstances<T>(instances);
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
throw new WebApplicationException(e);
}
}
示例3: removeService
import org.apache.curator.utils.ThreadUtils; //导入依赖的package包/类
@DELETE
@Path("v1/service/{name}/{id}")
public Response removeService(@PathParam("name") String name, @PathParam("id") String id)
{
try
{
ServiceInstance<T> instance = context.getServiceDiscovery().queryForInstance(name, id);
if ( instance != null )
{
//noinspection unchecked
context.getServiceDiscovery().unregisterService(instance);
}
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
log.error("Trying to delete service", e);
return Response.serverError().build();
}
return Response.ok().build();
}
示例4: getAll
import org.apache.curator.utils.ThreadUtils; //导入依赖的package包/类
@GET
@Path("v1/service/{name}")
@Produces(MediaType.APPLICATION_JSON)
public Response getAll(@PathParam("name") String name)
{
try
{
Collection<ServiceInstance<T>> instances = context.getServiceDiscovery().queryForInstances(name);
return Response.ok(new ServiceInstances<T>(instances)).build();
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
log.error(String.format("Trying to get instances from service (%s)", name), e);
return Response.serverError().build();
}
}
示例5: internalGet
import org.apache.curator.utils.ThreadUtils; //导入依赖的package包/类
private Response internalGet(String name, String id, boolean addDeprecationHeader)
{
try
{
ServiceInstance<T> instance = context.getServiceDiscovery().queryForInstance(name, id);
if ( instance == null )
{
return Response.status(Response.Status.NOT_FOUND).build();
}
Response.ResponseBuilder builder = Response.ok(instance);
if ( addDeprecationHeader )
{
builder = builder.header("Warning", "This API has been deprecated. Please see the updated spec for the replacement API.");
}
return builder.build();
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
log.error(String.format("Trying to get instance (%s) from service (%s)", id, name), e);
return Response.serverError().build();
}
}
示例6: checkService
import org.apache.curator.utils.ThreadUtils; //导入依赖的package包/类
private void checkService(String name)
{
try
{
Collection<ServiceInstance<Object>> instances = discovery.queryForInstances(name);
for ( ServiceInstance<Object> instance : instances )
{
if ( instance.getServiceType() == ServiceType.STATIC )
{
if ( (System.currentTimeMillis() - instance.getRegistrationTimeUTC()) > instanceRefreshMs )
{
discovery.unregisterService(instance);
}
}
}
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
log.error(String.format("GC for service: %s", name), e);
}
}
示例7: addFailedOperation
import org.apache.curator.utils.ThreadUtils; //导入依赖的package包/类
void addFailedOperation(T details)
{
if ( debugListener != null )
{
debugListener.pathAddedForGuaranteedOperation(details);
}
if ( client.getState() == CuratorFrameworkState.STARTED )
{
log.debug("Details being added to guaranteed operation set: " + details);
try
{
executeGuaranteedOperationInBackground(details);
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
addFailedOperation(details);
}
}
}
示例8: forEach
import org.apache.curator.utils.ThreadUtils; //导入依赖的package包/类
/**
* Utility - apply the given function to each listener. The function receives
* the listener as an argument.
*
* @param function function to call for each listener
*/
public void forEach(final Function<T, Void> function)
{
for ( final ListenerEntry<T> entry : listeners.values() )
{
entry.executor.execute
(
new Runnable()
{
@Override
public void run()
{
try
{
function.apply(entry.listener);
}
catch ( Throwable e )
{
ThreadUtils.checkInterrupted(e);
log.error(String.format("Listener (%s) threw an exception", entry.listener), e);
}
}
}
);
}
}
示例9: childEvent
import org.apache.curator.utils.ThreadUtils; //导入依赖的package包/类
@Override
public void childEvent(CuratorFramework client, TreeCacheEvent event)
{
try
{
internalChildEvent(event);
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
listenerContainer.forEach(l -> {
l.handleException(e);
return null;
});
}
}
示例10: notifyListeners
import org.apache.curator.utils.ThreadUtils; //导入依赖的package包/类
private void notifyListeners()
{
final byte[] localValue = getValue();
listeners.forEach
(
new Function<SharedValueListener, Void>()
{
@Override
public Void apply(SharedValueListener listener)
{
try
{
listener.valueHasChanged(SharedValue.this, localValue);
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
log.error("From SharedValue listener", e);
}
return null;
}
}
);
}
示例11: notifyListeners
import org.apache.curator.utils.ThreadUtils; //导入依赖的package包/类
private void notifyListeners()
{
final String path = getActualPath();
listeners.forEach(
new Function<PersistentNodeListener, Void>()
{
@Override
public Void apply(PersistentNodeListener listener)
{
try
{
listener.nodeCreated(path);
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
log.error("From PersistentNode listener", e);
}
return null;
}
}
);
}
示例12: callListeners
import org.apache.curator.utils.ThreadUtils; //导入依赖的package包/类
void callListeners(final PathChildrenCacheEvent event)
{
listeners.forEach
(
new Function<PathChildrenCacheListener, Void>()
{
@Override
public Void apply(PathChildrenCacheListener listener)
{
try
{
listener.childEvent(client, event);
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
handleException(e);
}
return null;
}
}
);
}
示例13: close
import org.apache.curator.utils.ThreadUtils; //导入依赖的package包/类
/**
* Close/end the cache.
*/
@Override
public void close()
{
if ( treeState.compareAndSet(TreeState.STARTED, TreeState.CLOSED) )
{
client.removeWatchers();
client.getConnectionStateListenable().removeListener(connectionStateListener);
listeners.clear();
executorService.shutdown();
try
{
root.wasDeleted();
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
handleException(e);
}
}
}
示例14: callListeners
import org.apache.curator.utils.ThreadUtils; //导入依赖的package包/类
private void callListeners(final TreeCacheEvent event)
{
listeners.forEach(new Function<TreeCacheListener, Void>()
{
@Override
public Void apply(TreeCacheListener listener)
{
try
{
listener.childEvent(client, event);
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
handleException(e);
}
return null;
}
});
}
示例15: publishEvent
import org.apache.curator.utils.ThreadUtils; //导入依赖的package包/类
private void publishEvent(final TreeCacheEvent event)
{
if ( treeState.get() != TreeState.CLOSED )
{
LOG.debug("publishEvent: {}", event);
executorService.submit(new Runnable()
{
@Override
public void run()
{
{
try
{
callListeners(event);
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
handleException(e);
}
}
}
});
}
}