public boolean connect(Properties connectionProps) { try { if (this.zooKeeper == null) { String connectString = connectionProps .getProperty(CONNECT_STRING); String sessionTimeout = connectionProps .getProperty(SESSION_TIMEOUT); String encryptionManager = connectionProps .getProperty(DATA_ENCRYPTION_MANAGER); String authScheme = connectionProps .getProperty(AUTH_SCHEME_KEY); String authData = connectionProps .getProperty(AUTH_DATA_KEY); if (connectString == null || sessionTimeout == null) { throw new IllegalArgumentException( "Both connect string and session timeout are required."); } if (encryptionManager == null) { this.encryptionManager = new BasicDataEncryptionManager(); } else { Class<?> clazz = Class.forName(encryptionManager); if (Arrays.asList(clazz.getInterfaces()).contains( DataEncryptionManager.class)) { this.encryptionManager = (DataEncryptionManager) Class .forName(encryptionManager).newInstance(); } else { throw new IllegalArgumentException( "Data encryption manager must implement DataEncryptionManager interface"); } } this.connectString = connectString; this.sessionTimeout = Integer.valueOf(sessionTimeout); this.zooKeeper = new ZooKeeperRetry(connectString, Integer .valueOf(sessionTimeout), new Watcher() { public void process(WatchedEvent event) { if (event.getState() == KeeperState.Expired) { connected = false; } } }); if (authData != null && authData.length() > 0){ this.zooKeeper.addAuthInfo(authScheme, authData.getBytes()); } ((ZooKeeperRetry) this.zooKeeper).setRetryLimit(10); connected = ((ZooKeeperRetry) this.zooKeeper).testConnection(); } } catch (Exception e) { connected = false; e.printStackTrace(); } if (!connected){ disconnect(); } return connected; }
public boolean connect(Properties connectionProps) { try { if (this.zooKeeper == null) { String connectString = connectionProps .getProperty(CONNECT_STRING); String sessionTimeout = connectionProps .getProperty(SESSION_TIMEOUT); String encryptionManager = connectionProps .getProperty(DATA_ENCRYPTION_MANAGER); String authScheme = connectionProps .getProperty(AUTH_SCHEME_KEY); String authData = connectionProps .getProperty(AUTH_DATA_KEY); if (connectString == null || sessionTimeout == null) { throw new IllegalArgumentException( "Both connect string and session timeout are required."); } if (encryptionManager == null) { this.encryptionManager = new BasicDataEncryptionManager(); } else { Class<?> clazz = Class.forName(encryptionManager); if (Arrays.asList(clazz.getInterfaces()).contains( DataEncryptionManager.class)) { this.encryptionManager = (DataEncryptionManager) Class .forName(encryptionManager).newInstance(); } else { throw new IllegalArgumentException( "Data encryption manager must implement DataEncryptionManager interface"); } } this.connectString = connectString; this.sessionTimeout = Integer.valueOf(sessionTimeout); this.zooKeeper = new ZooKeeperRetry(connectString, Integer .valueOf(sessionTimeout), new Watcher() { public void process(WatchedEvent event) { if (event.getState() == KeeperState.Expired) { connected = false; } } }); if (authData != null && authData.length() > 0){ this.zooKeeper.addAuthInfo(authScheme, authData.getBytes()); } ((ZooKeeperRetry) this.zooKeeper).setRetryLimit(10); connected = ((ZooKeeperRetry) this.zooKeeper).testConnection(); } } catch (Exception e) { connected = false; e.printStackTrace(); } if (!connected){ disconnect(); } else { this.nodesCache = new NodesCache(zooKeeper); } return connected; }
public boolean connect(Properties connectionProps) { try { if (this.zooKeeper == null) { String connectString = connectionProps .getProperty(CONNECT_STRING); String sessionTimeout = connectionProps .getProperty(SESSION_TIMEOUT); String encryptionManager = connectionProps .getProperty(DATA_ENCRYPTION_MANAGER); if (connectString == null || sessionTimeout == null) { throw new IllegalArgumentException( "Both connect string and session timeout are required."); } if (encryptionManager == null) { this.encryptionManager = new BasicDataEncryptionManager(); } else { Class<?> clazz = Class.forName(encryptionManager); if (Arrays.asList(clazz.getInterfaces()).contains( DataEncryptionManager.class)) { this.encryptionManager = (DataEncryptionManager) Class .forName(encryptionManager).newInstance(); } else { throw new IllegalArgumentException( "Data encryption manager must implement DataEncryptionManager interface"); } } this.connectString = connectString; this.sessionTimeout = Integer.valueOf(sessionTimeout); this.zooKeeper = new ZooKeeperRetry(connectString, Integer .valueOf(sessionTimeout), new Watcher() { public void process(WatchedEvent event) { if (event.getState() == KeeperState.Expired) { connected = false; } } }); ((ZooKeeperRetry) this.zooKeeper).setRetryLimit(10); connected = ((ZooKeeperRetry) this.zooKeeper).testConnection(); return connected; } } catch (Exception e) { e.printStackTrace(); } connected = false; return connected; }