Search in sources :

Example 36 with Timer

use of java.util.Timer in project ribbon by Netflix.

the class ResponseTimeWeightedRule method initialize.

void initialize(ILoadBalancer lb) {
    if (serverWeightTimer != null) {
        serverWeightTimer.cancel();
    }
    serverWeightTimer = new Timer("NFLoadBalancer-serverWeightTimer-" + name, true);
    serverWeightTimer.schedule(new DynamicServerWeightTask(), 0, serverWeightTaskTimerInterval);
    // do a initial run
    ServerWeight sw = new ServerWeight();
    sw.maintainWeights();
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

        public void run() {
            logger.info("Stopping NFLoadBalancer-serverWeightTimer-{}", name);
            serverWeightTimer.cancel();
        }
    }));
}
Also used : Timer(java.util.Timer)

Example 37 with Timer

use of java.util.Timer in project OpenRefine by OpenRefine.

the class RefineBrokerImpl method init.

@Override
public void init(ServletConfig config) throws Exception {
    logger.trace("> init");
    super.init(config);
    timer = new Timer();
    expirer = new Expirer();
    timer.schedule(expirer, 0, LOCK_EXPIRATION_CHECK_DELAY);
    String dataDir = config.getInitParameter("refine.data");
    if (dataDir == null)
        dataDir = "data";
    File dataPath = new File(dataDir);
    if (!dataPath.exists())
        dataPath.mkdirs();
    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setAllowCreate(true);
    envConfig.setTransactional(true);
    env = new Environment(dataPath, envConfig);
    StoreConfig storeConfig = new StoreConfig();
    storeConfig.setAllowCreate(true);
    storeConfig.setTransactional(true);
    projectStore = new EntityStore(env, "ProjectsStore", storeConfig);
    lockStore = new EntityStore(env, "LockStore", storeConfig);
    projectById = projectStore.getPrimaryIndex(String.class, Project.class);
    lockById = lockStore.getPrimaryIndex(String.class, Lock.class);
    locksByProject = lockStore.getSecondaryIndex(lockById, String.class, "pid");
    logger.trace("< init");
}
Also used : Timer(java.util.Timer) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Environment(com.sleepycat.je.Environment) StoreConfig(com.sleepycat.persist.StoreConfig) EntityStore(com.sleepycat.persist.EntityStore) File(java.io.File)

Example 38 with Timer

use of java.util.Timer in project canal by alibaba.

the class AbstractEventParser method startHeartBeat.

protected void startHeartBeat(ErosaConnection connection) {
    // 初始化
    lastEntryTime = 0L;
    if (timer == null) {
        // lazy初始化一下
        String name = String.format("destination = %s , address = %s , HeartBeatTimeTask", destination, runningInfo == null ? null : runningInfo.getAddress().toString());
        synchronized (AbstractEventParser.class) {
            // do this is ...
            if (timer == null) {
                timer = new Timer(name, true);
            }
        }
    }
    if (heartBeatTimerTask == null) {
        // fixed issue #56,避免重复创建heartbeat线程
        heartBeatTimerTask = buildHeartBeatTimeTask(connection);
        Integer interval = detectingIntervalInSeconds;
        timer.schedule(heartBeatTimerTask, interval * 1000L, interval * 1000L);
        logger.info("start heart beat.... ");
    }
}
Also used : Timer(java.util.Timer)

Example 39 with Timer

use of java.util.Timer in project Openfire by igniterealtime.

the class DatabaseManager method startDatabaseCleanLoop.

private void startDatabaseCleanLoop() {
    /*
		 * Database Cleaner thread and check for old log entries every 2 minute
		 */
    TimerTask task = new TimerTask() {

        @Override
        public void run() {
            cleanOldLogEntries();
        }
    };
    Timer timer = new Timer();
    timer.schedule(task, 2 * 60 * 1000, 2 * 60 * 1000);
}
Also used : TimerTask(java.util.TimerTask) Timer(java.util.Timer)

Example 40 with Timer

use of java.util.Timer in project Openfire by igniterealtime.

the class DiscoIQRegisteredProcessor method process.

@Override
public void process(Packet packet, final String subdomain, String to, String from) throws PacketRejectedException {
    Log.debug("Processing packet in DiscoIQRegisteredProcessor for " + subdomain);
    // Check if the jabber:iq:register is enabled in admin panel
    boolean isFeatureEnabled = JiveGlobals.getBooleanProperty("plugin.remoteroster.sparkDiscoInfo", false);
    if (!isFeatureEnabled) {
        Log.debug("Spark extension is deactivated. Won't change the disco#info");
        return;
    }
    final InterceptorManager interceptorManager = InterceptorManager.getInstance();
    final PacketInterceptor interceptor = new PacketInterceptor() {

        public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException {
            if (!processed && incoming) {
                if (packet instanceof IQ) {
                    IQ iqPacket = (IQ) packet;
                    Element packetElement = iqPacket.getChildElement();
                    if (packetElement == null)
                        return;
                    String ns = iqPacket.getChildElement().getNamespace().getURI();
                    if (iqPacket.getType().equals(IQ.Type.result) && ns.equals("jabber:iq:register") && iqPacket.getFrom().toString().equals(subdomain)) {
                        // Check if we are already registered
                        setRegistered(iqPacket.toString().contains("<registered/>"));
                        throw new PacketRejectedException();
                    } else if (iqPacket.getType().equals(IQ.Type.result) && ns.equals("http://jabber.org/protocol/disco#info") && iqPacket.getFrom().toString().equals(subdomain)) {
                        /*
							 * This is the answer of the disco#info from spark
							 * to our component. add the jabber:iq:register
							 * feature if we are registered
							 */
                        if (isRegistered()) {
                            Log.debug("Modifying disco#info packge to send registered iq feature to Spark user " + iqPacket.getTo().toString());
                            Attribute attribut = new DefaultAttribute("var", "jabber:iq:registered");
                            iqPacket.getChildElement().addElement("feature").add(attribut);
                        }
                    }
                }
            }
        }
    };
    Log.debug("Creating my own listener for jabber:iq:register result to external component " + subdomain);
    interceptorManager.addInterceptor(interceptor);
    IQ askComponent = new IQ();
    askComponent.setTo(to);
    askComponent.setFrom(from);
    askComponent.setType(IQ.Type.get);
    Element query = new DefaultElement(QName.get("query", "jabber:iq:register"));
    askComponent.setChildElement(query);
    // Remove the package intercepter in 1sec
    TimerTask removeInterceptorTask = new TimerTask() {

        @Override
        public void run() {
            Log.debug("Removing my created listener for jabber:iq:register. Component " + subdomain);
            interceptorManager.removeInterceptor(interceptor);
        }
    };
    Timer timer = new Timer();
    timer.schedule(removeInterceptorTask, 1000);
    // Send the register query to component
    dispatchPacket(askComponent);
}
Also used : Packet(org.xmpp.packet.Packet) DefaultAttribute(org.dom4j.tree.DefaultAttribute) Attribute(org.dom4j.Attribute) DefaultElement(org.dom4j.tree.DefaultElement) InterceptorManager(org.jivesoftware.openfire.interceptor.InterceptorManager) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketInterceptor(org.jivesoftware.openfire.interceptor.PacketInterceptor) TimerTask(java.util.TimerTask) Timer(java.util.Timer) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException) DefaultAttribute(org.dom4j.tree.DefaultAttribute) Session(org.jivesoftware.openfire.session.Session)

Aggregations

Timer (java.util.Timer)448 TimerTask (java.util.TimerTask)262 IOException (java.io.IOException)33 Date (java.util.Date)22 Test (org.junit.Test)15 File (java.io.File)11 ArrayList (java.util.ArrayList)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 JobExecutor (org.activiti.engine.impl.jobexecutor.JobExecutor)9 Intent (android.content.Intent)8 Location (android.location.Location)8 LocationListener (android.location.LocationListener)8 Bundle (android.os.Bundle)8 ActivitiException (org.activiti.engine.ActivitiException)8 View (android.view.View)7 InputMethodManager (android.view.inputmethod.InputMethodManager)7 ImageView (android.widget.ImageView)7 BufferedReader (java.io.BufferedReader)7 InputStreamReader (java.io.InputStreamReader)7