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


Java ThreadUtils类代码示例

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

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

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

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

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

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

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

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

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

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


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