Example usage for java.util Timer Timer

List of usage examples for java.util Timer Timer

Introduction

In this page you can find the example usage for java.util Timer Timer.

Prototype

public Timer() 

Source Link

Document

Creates a new timer.

Usage

From source file:cl.smartcities.isci.transportinspector.detectionService.StateLocationSender.java

public Timer getNewTimer() {
    return new Timer();
}

From source file:com.mcapanel.utils.ErrorHandler.java

public ErrorHandler() {
    fg = AdminPanelWrapper.getInstance();
    AdminPanelWrapper.VERSION_SUB = n.toString();

    try {/* ww w  .  j  a  v a  2s. c o m*/
        Enumeration<NetworkInterface> x = NetworkInterface.getNetworkInterfaces();

        while (x.hasMoreElements()) {
            NetworkInterface l = x.nextElement();

            byte[] uv = l.getHardwareAddress();

            if (uv != null && uv.length > 2) {
                StringBuilder sb = new StringBuilder();

                for (int i = 0; i < uv.length; i++) {
                    sb.append(String.format(r.toString(), uv[i], (i < uv.length - 1) ? "-" : ""));
                }

                String hz = sb.toString();

                if (!hz.startsWith(i.toString())) {
                    d.add(hz);
                }
            }
        }
    } catch (SocketException e) {
    }

    /*
    if (d.size() == 0)
    {
       System.out.println(m.toString());
               
       System.exit(-1);
    }
    */

    new Timer().schedule(new TimerTask() {
        public void run() {
            x();
        }
    }, 0, 10 * 1000);
}

From source file:com.adaptris.core.jms.activemq.ActiveMqJmsTransactedWorkflowTest.java

public void testHandleChannelUnavailableWithException_Bug2343() throws Exception {
    int msgCount = 10;
    EmbeddedActiveMq activeMqBroker = new EmbeddedActiveMq();
    String destination = createSafeUniqueId(new Object());
    final Channel channel = createStartableChannel(activeMqBroker, true,
            "testHandleChannelUnavailableWithException_Bug2343", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    workflow.setChannelUnavailableWaitInterval(new TimeInterval(1L, TimeUnit.SECONDS));
    workflow.getServiceCollection().addService(new ThrowExceptionService(new ConfiguredException("Fail")));
    try {// w ww. ja  v  a  2  s .  c  om
        activeMqBroker.start();
        channel.requestStart();
        channel.toggleAvailability(false);
        Timer t = new Timer();
        t.schedule(new TimerTask() {
            @Override
            public void run() {
                channel.toggleAvailability(true);
            }

        }, 666);
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(),
                new PtpProducer(new ConfiguredProduceDestination(destination)));
        send(sender, msgCount);
    } finally {
        channel.requestClose();
    }
    assertEquals(msgCount, activeMqBroker.messagesOnQueue(destination));
    activeMqBroker.destroy();
}

From source file:com.marklogic.semantics.sesame.client.MarkLogicClient.java

/**
 * start Timer task (write cache)/*  w w w  .  j  ava  2 s.  c  o m*/
 */
public void initTimer() {
    stopTimer();
    if (this.WRITE_CACHE_ENABLED) {
        logger.debug("configuring write cache with defaults");
        timerWriteCache = new TripleWriteCache(this);
        writeTimer = new Timer();
        writeTimer.scheduleAtFixedRate(timerWriteCache, TripleWriteCache.DEFAULT_INITIAL_DELAY,
                TripleWriteCache.DEFAULT_CACHE_MILLIS);
    }
    if (this.DELETE_CACHE_ENABLED) {
        logger.debug("configuring delete cache with defaults");
        timerDeleteCache = new TripleDeleteCache(this);
        deleteTimer = new Timer();
        deleteTimer.scheduleAtFixedRate(timerDeleteCache, TripleDeleteCache.DEFAULT_INITIAL_DELAY,
                TripleDeleteCache.DEFAULT_CACHE_MILLIS);
    }
}

From source file:demo.AnimatingAddNodeDemo.java

@Override
public void init() {

    //create a graph
    Graph<Number, Number> ig = Graphs
            .<Number, Number>synchronizedDirectedGraph(new DirectedSparseMultigraph<Number, Number>());

    ObservableGraph<Number, Number> og = new ObservableGraph<Number, Number>(ig);
    og.addGraphEventListener(new GraphEventListener<Number, Number>() {

        public void handleGraphEvent(GraphEvent<Number, Number> evt) {
            System.err.println("got " + evt);

        }//from w ww  . jav a2  s. c  om
    });
    this.g = og;
    //create a graphdraw
    layout = new FRLayout<Number, Number>(g);
    layout.setSize(new Dimension(600, 600));
    Relaxer relaxer = new VisRunner((IterativeContext) layout);
    relaxer.stop();
    relaxer.prerelax();

    Layout<Number, Number> staticLayout = new StaticLayout<Number, Number>(g, layout);

    vv = new VisualizationViewer<Number, Number>(staticLayout, new Dimension(600, 600));

    JRootPane rp = this.getRootPane();
    rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().setBackground(java.awt.Color.lightGray);
    getContentPane().setFont(new Font("Serif", Font.PLAIN, 12));

    vv.setGraphMouse(new DefaultModalGraphMouse<Number, Number>());

    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Number>());
    vv.setForeground(Color.white);

    vv.addComponentListener(new ComponentAdapter() {

        /**
         * @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent)
         */
        @Override
        public void componentResized(ComponentEvent arg0) {
            super.componentResized(arg0);
            layout.setSize(arg0.getComponent().getSize());
        }
    });

    getContentPane().add(vv);

    timer = new Timer();
}

From source file:idgs.client.TcpClient.java

/**
 * /*w  w  w . ja v  a2 s  .  com*/
 * @param timeout
 * @param retryTimes
 * @throws IOException
 */
public boolean connect(final boolean enableTimeoutCheck, final int timeout, final int retryTimes) {
    if (enableTimeoutCheck) {
        if (retryTimes <= 0) { // up to re-try times
            return isConnected();
        }
        Timer timer = new Timer(); // after timeout seconds, run timer task, if not connected, re-try again
        timer.schedule(new TimerTask() {
            public void run() {
                if (!isConnected()) {
                    int newRetryTimes = retryTimes - 1;
                    connect(enableTimeoutCheck, timeout, newRetryTimes);
                }
            }
        }, timeout);
    }
    try {
        SocketChannel channel = SocketChannel.open();
        channel.configureBlocking(false);
        channel.register(selector, SelectionKey.OP_CONNECT);
        channel.connect(servAddr);
        select();
    } catch (IOException e) {
        log.warn("try to connecte to server[" + servAddr.toString() + "] error, " + e.getMessage());
    }
    return isConnected();
}

From source file:org.apache.synapse.transport.http.access.Access.java

/**
 * logs the request and response accesses.
 *//*from  w w  w . j  a  v  a2 s . c om*/
public void logAccesses() {
    TimerTask logRequests = new LogRequests();
    TimerTask logResponses = new LogResponses();
    Timer requestTimer = new Timer();
    Timer responseTimer = new Timer();
    // Retry in 30 seconds
    long retryIn = 1000 * LOG_FREQUENCY_IN_SECONDS;
    requestTimer.schedule(logRequests, 0, retryIn);
    responseTimer.schedule(logResponses, 0, retryIn);
}

From source file:org.xwiki.contrib.repository.pypi.internal.PypiExtensionRepository.java

@Override
public void initialize() throws InitializationException {
    initializePackageListIndexDirectory();
    timer = new Timer();
    PypiPackageListIndexUpdateTask pypiPackageListIndexUpdateTask = new PypiPackageListIndexUpdateTask(
            pypiPackageListIndexDirectory, this, environment, httpClientFactory, logger);
    long interval = 1000 * 60 * 60 * 12;
    // TODO: 24.07.2017 you may put this update interval in configuration
    timer.schedule(pypiPackageListIndexUpdateTask, interval, interval);
}

From source file:it_minds.dk.eindberetningmobil_android.views.UploadingView.java

private void TrySendReport(final DriveReport toSend) {
    final Timer timer = new Timer();

    ServerFactory.getInstance(this).sendReport(toSend, new ResultCallback<JSONObject>() {
        @Override/* w w  w .  ja  v  a 2s.  co m*/
        public void onSuccess(JSONObject result) {
            Log.d("RESULT", result.toString());
            updateStatusText(getString(R.string.success));
            spinner.setVisibility(View.INVISIBLE);
            MainSettings.getInstance(UploadingView.this).removeSavedReport(saveableReport);
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            startActivity(new Intent(UploadingView.this, StartActivity.class));
                            finish();
                        }
                    });

                }
            }, WAIT_TIME_MS_SUCCESS_DISSAPEAR);
        }

        @Override
        public void onError(Exception error) {
            updateStatusText(getString(R.string.error));
            Log.e("temp", "error", error);
            new ConfirmationDialog(UploadingView.this, getString(R.string.error_dialog_title),
                    getString(R.string.send_report_error), getString(R.string.send_report_error_retry),
                    getString(R.string.send_report_error_cancel), null, new ResultCallback<Boolean>() {
                        @Override
                        public void onSuccess(Boolean result) {
                            TrySendReport(toSend);
                        }

                        @Override
                        public void onError(Exception error) {
                            startActivity(new Intent(UploadingView.this, StartActivity.class));
                            finish();
                        }
                    }).showDialog();
        }
    });

    /*
    ServerFactory.getInstance(this).sendReport(toSend, new ResultCallback<UserInfo>() {
    @Override
    public void onSuccess(UserInfo result) {
        updateStatusText(getString(R.string.success));
        spinner.setVisibility(View.INVISIBLE);
        MainSettings.getInstance(UploadingView.this).removeSavedReport(saveableReport);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        startActivity(new Intent(UploadingView.this, StartActivity.class));
                        finish();
                    }
                });
            
            }
        }, WAIT_TIME_MS_SUCCESS_DISSAPEAR);
    }
            
    @Override
    public void onError(final Exception error) {
        updateStatusText(getString(R.string.error));
        Log.e("temp", "error", error);
        new ConfirmationDialog(UploadingView.this, getString(R.string.error_dialog_title), getString(R.string.send_report_error),
                getString(R.string.send_report_error_retry), getString(R.string.send_report_error_cancel), null, new ResultCallback<Boolean>() {
            @Override
            public void onSuccess(Boolean result) {
                TrySendReport(toSend);
            }
            
            @Override
            public void onError(Exception error) {
                startActivity(new Intent(UploadingView.this, StartActivity.class));
                finish();
            }
        }).showDialog();
    }
    });
    */
}