use of org.apache.zookeeper.inspector.encryption.BasicDataEncryptionManager in project zookeeper by apache.
the class ZooInspectorManagerImpl method connect.
/*
* (non-Javadoc)
*
* @see
* org.apache.zookeeper.inspector.manager.ZooInspectorManager#connect(java
* .util.Properties)
*/
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;
}
Aggregations