}
public TraceServer(ServerConfiguration serverConfiguration, String hostname) throws Exception {
this.serverConfiguration = serverConfiguration;
AccumuloConfiguration conf = serverConfiguration.getConfiguration();
table = conf.get(Property.TRACE_TABLE);
Connector connector = null;
while (true) {
try {
String principal = conf.get(Property.TRACE_USER);
AuthenticationToken at;
Map<String,String> loginMap = conf.getAllPropertiesWithPrefix(Property.TRACE_TOKEN_PROPERTY_PREFIX);
if (loginMap.isEmpty()) {
Property p = Property.TRACE_PASSWORD;
at = new PasswordToken(conf.get(p).getBytes(Constants.UTF8));
} else {
Properties props = new Properties();
AuthenticationToken token = AccumuloClassLoader.getClassLoader().loadClass(conf.get(Property.TRACE_TOKEN_TYPE)).asSubclass(AuthenticationToken.class)
.newInstance();
int prefixLength = Property.TRACE_TOKEN_PROPERTY_PREFIX.getKey().length() + 1;
for (Entry<String,String> entry : loginMap.entrySet()) {
props.put(entry.getKey().substring(prefixLength), entry.getValue());
}
token.init(props);
at = token;
}
connector = serverConfiguration.getInstance().getConnector(principal, at);
if (!connector.tableOperations().exists(table)) {
connector.tableOperations().create(table);
IteratorSetting setting = new IteratorSetting(10, "ageoff", AgeOffFilter.class.getName());
AgeOffFilter.setTTL(setting, 7 * 24 * 60 * 60 * 1000l);
connector.tableOperations().attachIterator(table, setting);
}
connector.tableOperations().setProperty(table, Property.TABLE_FORMATTER_CLASS.getKey(), TraceFormatter.class.getName());
break;
} catch (Exception ex) {
log.info("Waiting to checking/create the trace table.", ex);
UtilWaitThread.sleep(1000);
}
}
this.connector = connector;
// make sure we refer to the final variable from now on.
connector = null;
int port = conf.getPort(Property.TRACE_PORT);
final ServerSocket sock = ServerSocketChannel.open().socket();
sock.setReuseAddress(true);
sock.bind(new InetSocketAddress(port));
final TServerTransport transport = new TServerSocket(sock);
TThreadPoolServer.Args options = new TThreadPoolServer.Args(transport);