本文整理汇总了Java中org.apache.curator.utils.ThreadUtils.checkInterrupted方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadUtils.checkInterrupted方法的具体用法?Java ThreadUtils.checkInterrupted怎么用?Java ThreadUtils.checkInterrupted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.curator.utils.ThreadUtils
的用法示例。
在下文中一共展示了ThreadUtils.checkInterrupted方法的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: close
import org.apache.curator.utils.ThreadUtils; //导入方法依赖的package包/类
@Override
public void close() throws IOException
{
log.debug("Closing");
CloseableUtils.closeQuietly(ensembleProvider);
try
{
zooKeeper.closeAndClear();
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
throw new IOException(e);
}
finally
{
isConnected.set(false);
}
}
示例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: acquire
import org.apache.curator.utils.ThreadUtils; //导入方法依赖的package包/类
/**
* <p>Acquire <code>qty</code> leases. If there are not enough leases available, this method
* blocks until either the maximum number of leases is increased enough or other clients/processes
* close enough leases.</p>
*
* <p>The client must close the leases when it is done with them. You should do this in a
* <code>finally</code> block. NOTE: You can use {@link #returnAll(Collection)} for this.</p>
*
* @param qty number of leases to acquire
* @return the new leases
* @throws Exception ZK errors, interruptions, etc.
*/
public Collection<Lease> acquire(int qty) throws Exception
{
Preconditions.checkArgument(qty > 0, "qty cannot be 0");
ImmutableList.Builder<Lease> builder = ImmutableList.builder();
try
{
while ( qty-- > 0 )
{
String path = internals.attemptLock(-1, null, null);
builder.add(makeLease(path));
}
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
returnAll(builder.build());
throw e;
}
return builder.build();
}
示例7: internalStart
import org.apache.curator.utils.ThreadUtils; //导入方法依赖的package包/类
private synchronized void internalStart()
{
if ( state.get() == State.STARTED )
{
client.getConnectionStateListenable().addListener(listener);
try
{
reset();
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
log.error("An error occurred checking resetting leadership.", e);
}
}
}
示例8: callWithRetry
import org.apache.curator.utils.ThreadUtils; //导入方法依赖的package包/类
@Override
public <T> T callWithRetry(CuratorZookeeperClient client, Callable<T> proc) throws Exception
{
client.internalBlockUntilConnectedOrTimedOut();
T result = null;
RetryLoop retryLoop = client.newRetryLoop();
while ( retryLoop.shouldContinue() )
{
try
{
result = proc.call();
retryLoop.markComplete();
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
retryLoop.takeException(e);
}
}
return result;
}
示例9: start
import org.apache.curator.utils.ThreadUtils; //导入方法依赖的package包/类
/**
* Start the group membership. Register thisId as a member and begin
* caching all members
*/
public void start() {
try {
doStart();
} catch (Exception e) {
ThreadUtils.checkInterrupted(e);
Throwables.propagate(e);
}
}
示例10: setData
import org.apache.curator.utils.ThreadUtils; //导入方法依赖的package包/类
/**
* Change the data stored in this instance's node
*
* @param data new data (cannot be null)
*/
public void setData(byte[] data) {
try {
pen.setData(data);
} catch (Exception e) {
ThreadUtils.checkInterrupted(e);
Throwables.propagate(e);
}
}
示例11: handleNewConnectionString
import org.apache.curator.utils.ThreadUtils; //导入方法依赖的package包/类
private void handleNewConnectionString(String newConnectionString)
{
log.info("Connection string changed to: " + newConnectionString);
new EventTrace("connection-string-changed", tracer.get(), getSessionId()).commit();
try
{
ZooKeeper zooKeeper = this.zooKeeper.getZooKeeper();
if ( zooKeeper == null )
{
log.warn("Could not update the connection string because getZooKeeper() returned null.");
}
else
{
if ( ensembleProvider.updateServerListEnabled() )
{
zooKeeper.updateServerList(newConnectionString);
}
else
{
reset();
}
}
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
queueBackgroundException(e);
}
}
示例12: putService
import org.apache.curator.utils.ThreadUtils; //导入方法依赖的package包/类
@PUT
@Path("v1/service/{name}/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response putService(ServiceInstance<T> instance, @PathParam("name") String name, @PathParam("id") String id)
{
if ( !instance.getId().equals(id) || !instance.getName().equals(name) )
{
log.info("Request where path id and/or name doesn't match entity");
return Response.status(Response.Status.BAD_REQUEST).build();
}
if ( instance.getServiceType().isDynamic() )
{
log.info("Service type cannot be dynamic");
return Response.status(Response.Status.BAD_REQUEST).build();
}
try
{
context.getServiceDiscovery().registerService(instance);
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
log.error("Trying to register service", e);
return Response.serverError().build();
}
return Response.status(Response.Status.CREATED).build();
}
示例13: handleExpiredSession
import org.apache.curator.utils.ThreadUtils; //导入方法依赖的package包/类
private void handleExpiredSession()
{
log.warn("Session expired event received");
new EventTrace("session-expired", tracer.get(), getSessionId()).commit();
try
{
reset();
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
queueBackgroundException(e);
}
}
示例14: start
import org.apache.curator.utils.ThreadUtils; //导入方法依赖的package包/类
/**
* Start the group membership. Register thisId as a member and begin
* caching all members
*/
public void start()
{
pen.start();
try
{
cache.start();
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
Throwables.propagate(e);
}
}
示例15: lockIf
import org.apache.curator.utils.ThreadUtils; //导入方法依赖的package包/类
private static void lockIf(CompletableFuture<Boolean> future, InterProcessLock lock, long timeout, TimeUnit unit)
{
try
{
future.complete(lock.acquire(timeout, unit));
}
catch ( Exception e )
{
ThreadUtils.checkInterrupted(e);
future.completeExceptionally(e);
}
}