Java Code Examples for org.apache.curator.framework.state.connectionstate#LOST

The following examples show how to use org.apache.curator.framework.state.connectionstate#LOST . 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: ZkLeaderSelector.java    From binlake with Apache License 2.0 6 votes vote down vote up
public void stateChanged(CuratorFramework client, ConnectionState newState) {
    try {
        LogUtils.warn.warn(client.getData().toString() + " state change to " + newState);
    } catch (Throwable exp) {
        // catch any null pointer exception
    }

    if (newState == ConnectionState.SUSPENDED || newState == ConnectionState.LOST) {
        try {
            refreshLogPos(); // 链接状态变更 则需要将最新的binlog offset 刷新到 zk
        } catch (Exception e) {
            // 更新binlog 位置异常
            LogUtils.error.error("state change to " + newState + " refresh log position error", e);
        }
        killWorkAndAbandonLeader();
    }
}
 
Example 2
Source File: LeaderSelectorListenerAdapter.java    From xian with Apache License 2.0 5 votes vote down vote up
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState)
{
    if ( (newState == ConnectionState.SUSPENDED) || (newState == ConnectionState.LOST) )
    {
        throw new CancelLeadershipException();
    }
}
 
Example 3
Source File: TestLeaderSelectorWithExecutor.java    From xian with Apache License 2.0 5 votes vote down vote up
@Override
public void stateChanged(CuratorFramework curatorFramework, ConnectionState newState)
{
    if ( (newState == ConnectionState.LOST) || (newState == ConnectionState.SUSPENDED) )
    {
        if ( ourThread != null )
        {
            ourThread.interrupt();
        }
    }
}
 
Example 4
Source File: ZKWatcher.java    From blog with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void stateChanged(CuratorFramework client, ConnectionState connectionState) {
	if (connectionState == ConnectionState.CONNECTED) {
		logger.info("connected established");
		countDownLatch.countDown();
	} else if (connectionState == ConnectionState.LOST) {
		logger.info("connection lost, waiting for reconection");
		try {
			reconnect();
		} catch (Exception e) {
			logger.error("reconnect error", e);
		}
	}

}
 
Example 5
Source File: ZkConnectionStatListener.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
public void stateChanged(CuratorFramework curatorFramework, ConnectionState state) {
    if (ConnectionState.SUSPENDED == state || ConnectionState.LOST == state) {
        logger.info(String.format("%s has lost connection from zookeeper", servicePath));
    } else if (ConnectionState.RECONNECTED == state) {
        try {
            PathUtil.rebalance(registryCenter, registryConfig, changeListener, servicePath);
        } catch (Exception e) {
            logger.error(String.format("%s connection reconnected to rebalance error", servicePath), e);
        }
    }
}
 
Example 6
Source File: DistributedSequenceHandler.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
    if (newState == ConnectionState.SUSPENDED || newState == ConnectionState.LOST) {
        this.isLeader = false;
        leaderExecutor.shutdownNow();
        throw new CancelLeadershipException();
    }
}
 
Example 7
Source File: ClusterLeaderManager.java    From cicada with MIT License 5 votes vote down vote up
@Override
public void stateChanged(final CuratorFramework client, final ConnectionState state) {
  if (state == ConnectionState.LOST || state == ConnectionState.SUSPENDED) {
    log.warn("connection state changed, now");
    isStop.set(true);
  }
}
 
Example 8
Source File: RegistryCenterConnectionStateListener.java    From shardingsphere-elasticjob-lite with Apache License 2.0 5 votes vote down vote up
@Override
public void stateChanged(final CuratorFramework client, final ConnectionState newState) {
    if (JobRegistry.getInstance().isShutdown(jobName)) {
        return;
    }
    JobScheduleController jobScheduleController = JobRegistry.getInstance().getJobScheduleController(jobName);
    if (ConnectionState.SUSPENDED == newState || ConnectionState.LOST == newState) {
        jobScheduleController.pauseJob();
    } else if (ConnectionState.RECONNECTED == newState) {
        serverService.persistOnline(serverService.isEnableServer(JobRegistry.getInstance().getJobInstance(jobName).getIp()));
        instanceService.persistOnline();
        executionService.clearRunningInfo(shardingService.getLocalShardingItems());
        jobScheduleController.resumeJob();
    }
}
 
Example 9
Source File: DefaultScheduler.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
    if ((newState == ConnectionState.SUSPENDED) || (newState == ConnectionState.LOST)) {
        try {
            shutdown();
        } catch (SchedulerException e) {
            throw new RuntimeException("failed to shutdown scheduler", e);
        }
    }
}
 
Example 10
Source File: TestLeaderSelectorWithExecutor.java    From curator with Apache License 2.0 5 votes vote down vote up
@Override
public void stateChanged(CuratorFramework curatorFramework, ConnectionState newState)
{
    if ( (newState == ConnectionState.LOST) || (newState == ConnectionState.SUSPENDED) )
    {
        if ( ourThread != null )
        {
            ourThread.interrupt();
        }
    }
}
 
Example 11
Source File: CuratorLeaderElectionManager.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void stateChanged(final CuratorFramework client, final ConnectionState newState) {
    logger.info("{} Connection State changed to {}", this, newState.name());

    if (newState == ConnectionState.SUSPENDED || newState == ConnectionState.LOST) {
        if (leader) {
            logger.info("Because Connection State was changed to {}, will relinquish leadership for role '{}'", newState, roleName);
        }

        setLeader(false);
    }

    super.stateChanged(client, newState);
}
 
Example 12
Source File: LeaderService.java    From curator-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void stateChanged(CuratorFramework curatorFramework, ConnectionState newState) {
    if (newState == ConnectionState.LOST || newState == ConnectionState.SUSPENDED) {
        LOG.debug("Lost leadership due to ZK state change to {}: {}", newState, getId());
        closeLeaderLatch();
    }
}
 
Example 13
Source File: ZKShardLockManager.java    From blueflood with Apache License 2.0 5 votes vote down vote up
public void stateChanged(CuratorFramework curatorFramework, ConnectionState connectionState) {
    log.info("Connection to Zookeeper toggled to state " + connectionState.toString());
    connected = connectionState == ConnectionState.CONNECTED || connectionState == ConnectionState.RECONNECTED;
    if (connectionState == ConnectionState.LOST) {
        log.error("Connection to Zookeeper toggled to state " + connectionState.toString());
        this.handleZookeeperConnectionFailed();
    } else if (connectionState == ConnectionState.RECONNECTED) {
        log.info("Reconnected to zookeeper, forcing lock scavenge");
        forceLockScavenge();
    } else {
        log.info("Connection to Zookeeper toggled to state " + connectionState.toString());
    }
}
 
Example 14
Source File: ZooKeeperCheckpointIDCounter.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
	if (newState == ConnectionState.SUSPENDED || newState == ConnectionState.LOST) {
		lastState = newState;
	}
}
 
Example 15
Source File: ZooKeeperCheckpointIDCounter.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
	if (newState == ConnectionState.SUSPENDED || newState == ConnectionState.LOST) {
		lastState = newState;
	}
}
 
Example 16
Source File: ZooKeeperTest.java    From curator-extensions with Apache License 2.0 4 votes vote down vote up
public static ConnectionTrigger lostTrigger() {
    return new ConnectionTrigger(ConnectionState.LOST);
}