use of org.apache.accumulo.core.util.Daemon in project accumulo by apache.
the class SecurityUtil method startTicketRenewalThread.
/**
* Start a thread that periodically attempts to renew the current Kerberos user's ticket.
*
* @param ugi
* The current Kerberos user.
* @param renewalPeriod
* The amount of time between attempting renewals.
*/
static void startTicketRenewalThread(final UserGroupInformation ugi, final long renewalPeriod) {
Thread t = new Daemon(new LoggingRunnable(renewalLog, new Runnable() {
@Override
public void run() {
while (true) {
try {
renewalLog.debug("Invoking renewal attempt for Kerberos ticket");
// While we run this "frequently", the Hadoop implementation will only perform the login at 80% of ticket lifetime.
ugi.checkTGTAndReloginFromKeytab();
} catch (IOException e) {
// Should failures to renew the ticket be retried more quickly?
renewalLog.error("Failed to renew Kerberos ticket", e);
}
// Wait for a bit before checking again.
try {
Thread.sleep(renewalPeriod);
} catch (InterruptedException e) {
renewalLog.error("Renewal thread interrupted", e);
Thread.currentThread().interrupt();
return;
}
}
}
}));
t.setName("Kerberos Ticket Renewal");
t.start();
}
use of org.apache.accumulo.core.util.Daemon in project accumulo by apache.
the class Halt method halt.
public static void halt(final int status, Runnable runnable) {
try {
// give ourselves a little time to try and do something
new Daemon() {
@Override
public void run() {
sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
Runtime.getRuntime().halt(status);
}
}.start();
if (runnable != null)
runnable.run();
Runtime.getRuntime().halt(status);
} finally {
// In case something else decides to throw a Runtime exception
Runtime.getRuntime().halt(-1);
}
}
use of org.apache.accumulo.core.util.Daemon in project accumulo by apache.
the class Monitor method run.
public void run(String hostname) {
Monitor.START_TIME = System.currentTimeMillis();
int[] ports = config.getSystemConfiguration().getPort(Property.MONITOR_PORT);
for (int port : ports) {
try {
log.debug("Creating monitor on port {}", port);
server = new EmbeddedWebServer(hostname, port);
server.addServlet(getDefaultServlet(), "/resources/*");
server.addServlet(getRestServlet(), "/rest/*");
server.addServlet(getViewServlet(), "/*");
server.start();
break;
} catch (Throwable ex) {
log.error("Unable to start embedded web server", ex);
}
}
if (!server.isRunning()) {
throw new RuntimeException("Unable to start embedded web server on ports: " + Arrays.toString(ports));
}
try {
getMonitorLock();
} catch (Exception e) {
log.error("Failed to get Monitor ZooKeeper lock");
throw new RuntimeException(e);
}
String advertiseHost = hostname;
if (advertiseHost.equals("0.0.0.0")) {
try {
advertiseHost = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
log.error("Unable to get hostname", e);
}
}
log.debug("Using {} to advertise monitor location in ZooKeeper", advertiseHost);
try {
String monitorAddress = HostAndPort.fromParts(advertiseHost, server.getPort()).toString();
ZooReaderWriter.getInstance().putPersistentData(ZooUtil.getRoot(instance) + Constants.ZMONITOR_HTTP_ADDR, monitorAddress.getBytes(UTF_8), NodeExistsPolicy.OVERWRITE);
log.info("Set monitor address in zookeeper to {}", monitorAddress);
} catch (Exception ex) {
log.error("Unable to set monitor HTTP address in zookeeper", ex);
}
if (null != advertiseHost) {
LogService.startLogListener(Monitor.getContext().getConfiguration(), instance.getInstanceID(), advertiseHost);
} else {
log.warn("Not starting log4j listener as we could not determine address to use");
}
new Daemon(new LoggingRunnable(log, new ZooKeeperStatus()), "ZooKeeperStatus").start();
// need to regularly fetch data so plot data is updated
new Daemon(new LoggingRunnable(log, new Runnable() {
@Override
public void run() {
while (true) {
try {
Monitor.fetchData();
} catch (Exception e) {
log.warn("{}", e.getMessage(), e);
}
sleepUninterruptibly(333, TimeUnit.MILLISECONDS);
}
}
}), "Data fetcher").start();
new Daemon(new LoggingRunnable(log, new Runnable() {
@Override
public void run() {
while (true) {
try {
Monitor.fetchScans();
} catch (Exception e) {
log.warn("{}", e.getMessage(), e);
}
sleepUninterruptibly(5, TimeUnit.SECONDS);
}
}
}), "Scan scanner").start();
monitorInitialized.set(true);
}
Aggregations