Java Code Examples for org.apache.curator.x.discovery.ServiceInstance#getRegistrationTimeUTC()

The following examples show how to use org.apache.curator.x.discovery.ServiceInstance#getRegistrationTimeUTC() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InstanceCleanup.java    From curator with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 2
Source File: JsonInstanceSerializer.java    From curator with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize(ServiceInstance<T> instance) throws Exception
{
    if ( compatibleSerializationMode )
    {
        OldServiceInstance<T> compatible = new OldServiceInstance<T>(instance.getName(), instance.getId(), instance.getAddress(), instance.getPort(), instance.getSslPort(), instance.getPayload(), instance.getRegistrationTimeUTC(), instance.getServiceType(), instance.getUriSpec());
        return mapper.writeValueAsBytes(compatible);
    }
    return mapper.writeValueAsBytes(instance);
}