Example usage for java.util TimerTask TimerTask

List of usage examples for java.util TimerTask TimerTask

Introduction

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

Prototype

protected TimerTask() 

Source Link

Document

Creates a new timer task.

Usage

From source file:org.powertac.visualizer.services.VisualizerServiceTournament.java

@Override
public void afterPropertiesSet() throws Exception {
    Timer initTimer = new Timer(true);
    // delay to let deployment complete
    initTimer.schedule(new TimerTask() {
        @Override// w ww  . ja  v  a 2s . co m
        public void run() {
            init();
        }
    }, 20000l);
}

From source file:org.droidpres.activity.TransferActivity.java

public void swichWiFi() {
    mWiFiConnectFlag = false;//www .j av a 2 s  . c  o m

    IntentFilter filter = mFilter;
    WiFiStateReceiver receiver = mWifiStateReceiver;
    if (receiver == null) {
        receiver = new WiFiStateReceiver();
        mWifiStateReceiver = receiver;
        filter = new IntentFilter();
        filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
        filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
        mFilter = filter;
    }
    this.registerReceiver(receiver, filter);
    getWiFiManager().setWifiEnabled(mWiFiFlag);

    if (mWiFiFlag) {
        new Timer().schedule(new TimerTask() {

            @Override
            public void run() {
                if (!mWiFiConnectFlag) {
                    mWiFiFlag = false;
                    getWiFiManager().setWifiEnabled(mWiFiFlag);
                }
            }
        }, 90000);
    }
}

From source file:io.druid.indexing.common.task.AppenderatorDriverRealtimeIndexTask.java

private void setupTimeoutAlert() {
    if (spec.getTuningConfig().getAlertTimeout() > 0) {
        Timer timer = new Timer("RealtimeIndexTask-Timer", true);
        timer.schedule(new TimerTask() {
            @Override//from  ww w .  j  a v a 2 s .  c  o m
            public void run() {
                log.makeAlert(
                        "RealtimeIndexTask for dataSource [%s] hasn't finished in configured time [%d] ms.",
                        spec.getDataSchema().getDataSource(), spec.getTuningConfig().getAlertTimeout()).emit();
            }
        }, spec.getTuningConfig().getAlertTimeout());
    }
}

From source file:com.codefollower.lealone.omid.client.TSOClient.java

@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    LOG.error("Unexpected exception", e.getCause());

    synchronized (state) {

        if (state == State.CONNECTING) {
            state = State.RETRY_CONNECT_WAIT;
            if (LOG.isDebugEnabled()) {
                LOG.debug("Retrying connect in " + retryDelayMs + "ms " + retries);
            }// ww  w .  j  ava  2s  . c  o  m
            try {
                retryTimer.schedule(new TimerTask() {
                    public void run() {
                        synchronized (state) {
                            state = State.DISCONNECTED;
                            try {
                                connectIfNeeded();
                            } catch (IOException e) {
                                bailout(e);
                            }
                        }
                    }
                }, retryDelayMs);
            } catch (Exception cause) {
                bailout(cause);
            }
        } else {
            LOG.error("Exception on channel", e.getCause());
        }
    }
}

From source file:sx.blah.discord.handle.impl.obj.Channel.java

@Override
public void setTypingStatus(boolean typing) {
    if (typing) {
        TimerTask task = new TimerTask() {
            @Override// w  w  w .  j  a  v a2  s .com
            public void run() {
                if (!isPrivate() && isDeleted()) {
                    this.cancel();
                    return;
                }
                try {
                    Discord4J.LOGGER.trace(LogMarkers.HANDLE, "Sending TypingStatus Keep Alive");
                    ((DiscordClientImpl) client).REQUESTS.POST
                            .makeRequest(DiscordEndpoints.CHANNELS + getLongID() + "/typing");
                } catch (RateLimitException | DiscordException e) {
                    Discord4J.LOGGER.error(LogMarkers.HANDLE, "Discord4J Internal Exception", e);
                }
            }
        };

        if (typingTask.compareAndSet(null, task)) {
            typingTimer.scheduleAtFixedRate(task, 0, TIME_FOR_TYPE_STATUS);
        }
    } else {
        TimerTask oldTask = typingTask.getAndSet(null);
        if (oldTask != null) {
            oldTask.cancel();
        }
    }
}

From source file:com.connectsdk.service.DLNAService.java

@Override
public void getDuration(final DurationListener listener) {
    getPositionInfo(new PositionInfoListener() {

        @Override//w  w w. j  av  a 2s. c om
        public void onGetPositionInfoSuccess(String positionInfoXml) {
            String strDuration = parseData(positionInfoXml, "TrackDuration");

            String trackMetaData = parseData(positionInfoXml, "TrackMetaData");
            MediaInfo info = DLNAMediaInfoParser.getMediaInfo(trackMetaData);
            // Check if duration we get not equals 0 or media is image, otherwise wait 1 second and try again
            if ((!strDuration.equals("0:00:00")) || (info.getMimeType().contains("image"))) {
                long milliTimes = convertStrTimeFormatToLong(strDuration);

                Util.postSuccess(listener, milliTimes);
            } else
                new Timer().schedule(new TimerTask() {

                    @Override
                    public void run() {
                        getDuration(listener);

                    }
                }, 1000);

        }

        @Override
        public void onGetPositionInfoFailed(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    });
}

From source file:com.thebuzzmedia.exiftool.ExifToolNew3.java

/**
 * Used to startup the external ExifToolNew3 process and open the read/write streams used to communicate with it
 * when {@link Feature#STAY_OPEN} is enabled. This method has no effect if the stay open feature is not enabled.
 *//*  w w  w.  j  av a  2s  . c om*/
// @Override
// public void startup() {
// if (featureSet.contains(Feature.STAY_OPEN)) {
// shuttingDown.set(false);
// ensureProcessRunning();
// }
// }

private void ensureProcessRunning() {
    if (process == null || process.isClosed()) {
        synchronized (this) {
            if (process == null || process.isClosed()) {
                LOG.debug(
                        "Starting daemon ExifToolNew3 process and creating read/write streams (this only happens once)...");
                process = ExifProcess.startup(exifCmd, charset);
            }
        }
    }
    if (processCleanupDelay > 0) {
        synchronized (this) {
            if (currentCleanupTask != null) {
                currentCleanupTask.cancel();
                currentCleanupTask = null;
            }
            currentCleanupTask = new TimerTask() {
                @Override
                public void run() {
                    LOG.info("Auto cleanup task running...");
                    process.close();
                }
            };
            cleanupTimer.schedule(currentCleanupTask, processCleanupDelay);
        }
    }
}

From source file:com.carapp.login.splashActivity.java

private void getClientBranch() {

    MultipartEntity entity = new MultipartEntity();
    try {/*  www . ja  v a  2 s . c  om*/
        entity.addPart("action", new StringBody("init_config"));

        new AsyncWebServiceProcessingTask(context, entity, messagecheck, new AsynckCallback() {

            @Override
            public void run(String result) {
                if (UIUtils.checkJson(result, context)) {
                    try {
                        JSONObject jsonObject = new JSONObject(result);
                        if (jsonObject.optString("satus").equals("success")) {
                            PdfInfo.client = jsonObject.optString("client");
                            PdfInfo.branch = jsonObject.optString("branch");
                            Util.showCustomDialogWithoutButton(context, "Message", messagechecksucces,
                                    new Callback2() {
                                        @Override
                                        public void ok(final Dialog dialog) {
                                            final Handler handler = new Handler();
                                            final Runnable runnable = new Runnable() {
                                                @Override
                                                public void run() {
                                                    dialog.dismiss();
                                                    new AsyncWebServiceProcessingTask(context, null,
                                                            "Please wait while checking date",
                                                            new AsynckCallback() {

                                                                @Override
                                                                public void run(String result) {
                                                                    Log.e("date", "" + result);
                                                                    String sysdate = android.text.format.DateFormat
                                                                            .format("dd/MM/yyyy",
                                                                                    new java.util.Date())
                                                                            .toString();
                                                                    if (result.equals(sysdate)) {
                                                                        Toast.makeText(context, "date match",
                                                                                Toast.LENGTH_SHORT).show();
                                                                        new AsyncWebServiceProcessingTask(
                                                                                context, null, messagecheckday,
                                                                                new AsynckCallback() {
                                                                                    @Override
                                                                                    public void run(
                                                                                            String result) {
                                                                                        int day = Integer
                                                                                                .parseInt(
                                                                                                        result);
                                                                                        Calendar calendar = Calendar
                                                                                                .getInstance();
                                                                                        int Today = calendar
                                                                                                .get(Calendar.DAY_OF_WEEK);
                                                                                        day++;
                                                                                        if (day == Today) {
                                                                                            Toast.makeText(
                                                                                                    context,
                                                                                                    "day is correct",
                                                                                                    Toast.LENGTH_SHORT)
                                                                                                    .show();
                                                                                            String ma_a = null;

                                                                                            try {
                                                                                                WifiManager wiman = (WifiManager) getSystemService(
                                                                                                        Context.WIFI_SERVICE);
                                                                                                ma_a = wiman
                                                                                                        .getConnectionInfo()
                                                                                                        .getMacAddress();
                                                                                                Log.i(t, ""
                                                                                                        + ma_a);
                                                                                            } catch (Exception e1) {

                                                                                                e1.printStackTrace();
                                                                                                Log.i(t, " "
                                                                                                        + e1);
                                                                                            }
                                                                                            MultipartEntity entity = new MultipartEntity();
                                                                                            try {
                                                                                                entity.addPart(
                                                                                                        "action",
                                                                                                        new StringBody(
                                                                                                                "device_authentication"));
                                                                                                entity.addPart(
                                                                                                        "mac_address",
                                                                                                        new StringBody(
                                                                                                                ma_a));
                                                                                                new AsyncWebServiceProcessingTask(
                                                                                                        context,
                                                                                                        entity,
                                                                                                        "Checking License",
                                                                                                        new AsynckCallback() {

                                                                                                            @Override
                                                                                                            public void run(
                                                                                                                    String result) {

                                                                                                                if (UIUtils
                                                                                                                        .checkJson(
                                                                                                                                result,
                                                                                                                                context)) {
                                                                                                                    try {
                                                                                                                        JSONObject jsonObject = new JSONObject(
                                                                                                                                result);
                                                                                                                        if (jsonObject
                                                                                                                                .optString(
                                                                                                                                        "satus")
                                                                                                                                .equals("success")) {
                                                                                                                            Toast.makeText(
                                                                                                                                    context,
                                                                                                                                    "LicenseCheck sucesses",
                                                                                                                                    Toast.LENGTH_SHORT)
                                                                                                                                    .show();
                                                                                                                            startActivity(
                                                                                                                                    new Intent(
                                                                                                                                            context,
                                                                                                                                            LoginActivity.class));
                                                                                                                            finish();

                                                                                                                        } else if (jsonObject
                                                                                                                                .optString(
                                                                                                                                        "satus")
                                                                                                                                .equals("error")) {
                                                                                                                            Util.showCustomDialog(
                                                                                                                                    context,
                                                                                                                                    "Error",
                                                                                                                                    jsonObject
                                                                                                                                            .optString(
                                                                                                                                                    "msg"));

                                                                                                                        }

                                                                                                                    } catch (Exception e) {

                                                                                                                        e.printStackTrace();

                                                                                                                    }

                                                                                                                }
                                                                                                            }
                                                                                                        }).execute(
                                                                                                                PdfInfo.newjobcard);

                                                                                            } catch (Exception e) {

                                                                                                e.printStackTrace();
                                                                                            }

                                                                                        } else {
                                                                                            Util.showCustomDialogWithoutButton(
                                                                                                    context,
                                                                                                    "Error",
                                                                                                    messagecheckdayerror
                                                                                                            + " server day is "
                                                                                                            + day
                                                                                                            + " but your device is"
                                                                                                            + Today,
                                                                                                    new Callback2() {

                                                                                                        @Override
                                                                                                        public void ok(
                                                                                                                final Dialog dialog) {

                                                                                                            final Handler handler = new Handler();
                                                                                                            final Runnable runnable = new Runnable() {
                                                                                                                @Override
                                                                                                                public void run() {
                                                                                                                    dialog.dismiss();
                                                                                                                    finish();
                                                                                                                }
                                                                                                            };
                                                                                                            handler.postDelayed(
                                                                                                                    runnable,
                                                                                                                    5000);

                                                                                                        }
                                                                                                    });
                                                                                        }

                                                                                    }
                                                                                }).execute(PdfInfo.dayaddress);
                                                                    } else {

                                                                        Util.showCustomDialogWithoutButton(
                                                                                context, "Error",
                                                                                messagecheckdateerror
                                                                                        + " server date is "
                                                                                        + result
                                                                                        + " but device date is "
                                                                                        + sysdate,
                                                                                new Callback2() {

                                                                                    @Override
                                                                                    public void ok(
                                                                                            final Dialog dialog) {

                                                                                        new Timer().schedule(
                                                                                                new TimerTask() {

                                                                                                    @Override
                                                                                                    public void run() {
                                                                                                        dialog.dismiss();
                                                                                                        finish();

                                                                                                    }
                                                                                                }, 5000);
                                                                                    }
                                                                                });

                                                                    }
                                                                }
                                                            }).execute(PdfInfo.dateaddress);

                                                }
                                            };
                                            handler.postDelayed(runnable, 5000);

                                        }
                                    });

                        } else if (jsonObject.optString("satus").equals("error")) {
                            Util.showCustomDialogWithoutButton(context, "Message", messagechecksucces,
                                    new Callback2() {

                                        @Override
                                        public void ok(final Dialog dialog) {

                                            new Timer().schedule(new TimerTask() {

                                                @Override
                                                public void run() {
                                                    dialog.dismiss();
                                                    finish();

                                                }
                                            }, 5000);
                                        }
                                    });

                        }

                    } catch (Exception e) {

                        e.printStackTrace();

                    }

                }
            }
        }).execute(PdfInfo.newjobcard);

    } catch (Exception e) {

        e.printStackTrace();
    }

}

From source file:org.anhonesteffort.flock.SubscriptionGoogleFragment.java

private void handleStartPerpetualRefresh() {
    intervalTimer = new Timer();
    TimerTask uiTask = new TimerTask() {

        @Override/*from www  .  j  a v a 2 s  .  c om*/
        public void run() {
            uiHandler.post(refreshUiRunnable);
        }

    };

    intervalTimer.schedule(uiTask, 0, 10000);
}

From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.Iec61850SsldDeviceService.java

@Override
public void setTransition(final SetTransitionDeviceRequest deviceRequest,
        final DeviceResponseHandler deviceResponseHandler) {
    try {//  w  w  w .ja  va  2  s. c  o  m
        final DeviceConnection deviceConnection = this.connectToDevice(deviceRequest);

        new Iec61850TransitionCommand().transitionDevice(this.iec61850Client, deviceConnection,
                deviceRequest.getTransitionTypeContainer());

        this.createSuccessfulDefaultResponse(deviceRequest, deviceResponseHandler);

        // Enabling device reporting. This is placed here because this is
        // called twice a day.
        new Iec61850EnableReportingCommand()
                .enableReportingOnDeviceWithoutUsingSequenceNumber(this.iec61850Client, deviceConnection);
        // Don't disconnect now! The device should be able to send reports.
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    new Iec61850ClearReportCommand().clearReportOnDevice(deviceConnection);
                } catch (final ProtocolAdapterException e) {
                    LOGGER.error(
                            "Unable to clear report for device: " + deviceRequest.getDeviceIdentification(), e);
                }
                Iec61850SsldDeviceService.this.iec61850DeviceConnectionService
                        .disconnect(deviceRequest.getDeviceIdentification());
            }
        }, this.disconnectDelay);
    } catch (final ConnectionFailureException se) {
        this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, se);
    } catch (final Exception e) {
        this.handleException(deviceRequest, deviceResponseHandler, e);
    }
}