当前位置: 首页>>代码示例>>Java>>正文


Java ThreadUtils.checkInterrupted方法代码示例

本文整理汇总了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;
}
 
开发者ID:apache,项目名称:curator,代码行数:23,代码来源:JsonServiceInstanceMarshaller.java

示例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);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:23,代码来源:JsonServiceInstancesMarshaller.java

示例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();
}
 
开发者ID:apache,项目名称:curator,代码行数:22,代码来源:DiscoveryResource.java

示例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);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:21,代码来源:ConnectionState.java

示例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();
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:24,代码来源:DiscoveryResource.java

示例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();
}
 
开发者ID:apache,项目名称:curator,代码行数:34,代码来源:InterProcessSemaphore.java

示例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);
        }
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:17,代码来源:LeaderLatch.java

示例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;
}
 
开发者ID:apache,项目名称:curator,代码行数:24,代码来源:StandardConnectionHandlingPolicy.java

示例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);
    }
}
 
开发者ID:stormpath,项目名称:samza-spring-boot-starter,代码行数:13,代码来源:SequentialGroupMember.java

示例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);
    }
}
 
开发者ID:stormpath,项目名称:samza-spring-boot-starter,代码行数:14,代码来源:SequentialGroupMember.java

示例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);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:31,代码来源:ConnectionState.java

示例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();
}
 
开发者ID:apache,项目名称:curator,代码行数:32,代码来源:DiscoveryResource.java

示例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);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:16,代码来源:ConnectionState.java

示例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);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:18,代码来源:GroupMember.java

示例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);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:13,代码来源:AsyncWrappers.java


注:本文中的org.apache.curator.utils.ThreadUtils.checkInterrupted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。