Search in sources :

Example 46 with Timer

use of java.util.Timer in project Core by iConomy.

the class iConomy method onEnable.

public void onEnable() {
    final long startTime = System.nanoTime();
    final long endTime;
    try {
        // Localize locale to prevent issues.
        Locale.setDefault(Locale.US);
        // Server & Terminal Support
        Server = getServer();
        if (getServer().getServerName().equalsIgnoreCase("craftbukkit")) {
            TerminalSupport = ((CraftServer) getServer()).getReader().getTerminal().isANSISupported();
        }
        // Get general plugin information
        info = getDescription();
        // Plugin directory setup
        directory = getDataFolder();
        if (!directory.exists())
            directory.mkdir();
        // Extract Files
        Common.extract("Config.yml", "Template.yml");
        // Setup Configuration
        Constants.load(new File(directory, "Config.yml"));
        // Setup Template
        Template = new Template(directory.getPath(), "Template.yml");
        // Upgrade Template to 6.0.9b
        LinkedHashMap<String, String> nodes = new LinkedHashMap<String, String>();
        nodes.put("top.opening", "<green>-----[ <white>Wealthiest Accounts <green>]-----");
        nodes.put("top.item", "<gray>+i. <green>+name <gray>- <white>+amount");
        try {
            Template.update(nodes);
        } catch (IOException ex) {
            System.out.println(ex.getMessage());
        }
        // Check Drivers if needed
        Type type = Database.getType(Constants.Nodes.DatabaseType.toString());
        if (!(type.equals(Type.InventoryDB) || type.equals(Type.MiniDB))) {
            Drivers driver = null;
            switch(type) {
                case H2DB:
                    driver = Constants.Drivers.H2;
                    break;
                case MySQL:
                    driver = Constants.Drivers.MySQL;
                    break;
                case SQLite:
                    driver = Constants.Drivers.SQLite;
                    break;
                case Postgre:
                    driver = Constants.Drivers.Postgre;
                    break;
            }
            if (driver != null)
                if (!(new File("lib", driver.getFilename()).exists())) {
                    System.out.println("[iConomy] Downloading " + driver.getFilename() + "...");
                    wget.fetch(driver.getUrl(), driver.getFilename());
                    System.out.println("[iConomy] Finished Downloading.");
                }
        }
        // Setup Commands
        Commands.add("/money +name", new Money(this));
        Commands.setPermission("money", "iConomy.holdings");
        Commands.setPermission("money+", "iConomy.holdings.others");
        Commands.setHelp("money", new String[] { "", "Check your balance." });
        Commands.setHelp("money+", new String[] { " [name]", "Check others balance." });
        Commands.add("/money -h|?|help +command", new Help(this));
        Commands.setPermission("help", "iConomy.help");
        Commands.setHelp("help", new String[] { " (command)", "For Help & Information." });
        Commands.add("/money -t|top", new Top(this));
        Commands.setPermission("top", "iConomy.top");
        Commands.setHelp("top", new String[] { "", "View top economical accounts." });
        Commands.add("/money -p|pay +name +amount:empty", new Payment(this));
        Commands.setPermission("pay", "iConomy.payment");
        Commands.setHelp("pay", new String[] { " [name] [amount]", "Send money to others." });
        Commands.add("/money -c|create +name", new Create(this));
        Commands.setPermission("create", "iConomy.accounts.create");
        Commands.setHelp("create", new String[] { " [name]", "Create an account." });
        Commands.add("/money -r|remove +name", new Remove(this));
        Commands.setPermission("remove", "iConomy.accounts.remove");
        Commands.setHelp("remove", new String[] { " [name]", "Remove an account." });
        Commands.add("/money -g|give +name +amount:empty", new Give(this));
        Commands.setPermission("give", "iConomy.accounts.give");
        Commands.setHelp("give", new String[] { " [name] [amount]", "Give money." });
        Commands.add("/money -t|take +name +amount:empty", new Take(this));
        Commands.setPermission("take", "iConomy.accounts.take");
        Commands.setHelp("take", new String[] { " [name] [amount]", "Take money." });
        Commands.add("/money -s|set +name +amount:empty", new Set(this));
        Commands.setPermission("set", "iConomy.accounts.set");
        Commands.setHelp("set", new String[] { " [name] [amount]", "Set account balance." });
        Commands.add("/money -u|status +name +status:empty", new Status(this));
        Commands.setPermission("status", "iConomy.accounts.status");
        Commands.setPermission("status+", "iConomy.accounts.status.set");
        Commands.setHelp("status", new String[] { " [name] (status)", "Check/Set account status." });
        Commands.add("/money -x|purge", new Purge(this));
        Commands.setPermission("purge", "iConomy.accounts.purge");
        Commands.setHelp("purge", new String[] { "", "Purge all accounts with initial holdings." });
        Commands.add("/money -e|empty", new Empty(this));
        Commands.setPermission("empty", "iConomy.accounts.empty");
        Commands.setHelp("empty", new String[] { "", "Empty database of accounts." });
        // Setup Database.
        try {
            Database = new Database(Constants.Nodes.DatabaseType.toString(), Constants.Nodes.DatabaseUrl.toString(), Constants.Nodes.DatabaseUsername.toString(), Constants.Nodes.DatabasePassword.toString());
            // If it doesn't exist, Create one.
            if (Database.isSQL()) {
                if (!Database.tableExists(Constants.Nodes.DatabaseTable.toString())) {
                    String SQL = Common.resourceToString("SQL/Core/Create-Table-" + Database.getType().toString().toLowerCase() + ".sql");
                    SQL = String.format(SQL, Constants.Nodes.DatabaseTable.getValue());
                    try {
                        QueryRunner run = new QueryRunner();
                        Connection c = iConomy.Database.getConnection();
                        try {
                            run.update(c, SQL);
                        } catch (SQLException ex) {
                            System.out.println("[iConomy] Error creating database: " + ex);
                        } finally {
                            DbUtils.close(c);
                        }
                    } catch (SQLException ex) {
                        System.out.println("[iConomy] Database Error: " + ex);
                    }
                }
            } else {
                this.onConversion();
            }
        } catch (MissingDriver ex) {
            System.out.println(ex.getMessage());
        }
        getServer().getPluginManager().registerEvents(new players(), this);
    } finally {
        endTime = System.nanoTime();
    }
    // Setup Interest
    if (Constants.Nodes.Interest.getBoolean()) {
        Thrun.init(new Runnable() {

            public void run() {
                long time = Constants.Nodes.InterestTime.getLong() * 1000L;
                Interest = new Timer();
                Interest.scheduleAtFixedRate(new Interest(getDataFolder().getPath()), time, time);
            }
        });
    }
    if (Constants.Nodes.Purging.getBoolean()) {
        Thrun.init(new Runnable() {

            public void run() {
                Queried.purgeDatabase();
                System.out.println("[" + info.getName() + " - " + Constants.Nodes.CodeName.toString() + "] Purged accounts with default balance.");
            }
        });
    }
    final long duration = endTime - startTime;
    // Finish
    System.out.println("[" + info.getName() + " - " + Constants.Nodes.CodeName.toString() + "] Enabled (" + Common.readableProfile(duration) + ")");
}
Also used : ResultSet(java.sql.ResultSet) Drivers(com.iCo6.Constants.Drivers) SQLException(java.sql.SQLException) Template(com.iCo6.util.Template) LinkedHashMap(java.util.LinkedHashMap) Interest(com.iCo6.system.Interest) Database(com.iCo6.IO.Database) com.iCo6.listeners.players(com.iCo6.listeners.players) Connection(java.sql.Connection) IOException(java.io.IOException) QueryRunner(com.iCo6.util.org.apache.commons.dbutils.QueryRunner) Type(com.iCo6.IO.Database.Type) Timer(java.util.Timer) MissingDriver(com.iCo6.IO.exceptions.MissingDriver) File(java.io.File) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile)

Example 47 with Timer

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

the class RegisterProcessing method processOK.

void processOK(ClientTransaction clientTransatcion, Response response) {
    isRegistered = true;
    FromHeader fromHeader = ((FromHeader) response.getHeader(FromHeader.NAME));
    Address address = fromHeader.getAddress();
    int expires = 0;
    if (!isUnregistering) {
        ContactHeader contactHeader = (ContactHeader) response.getHeader(ContactHeader.NAME);
        // TODO check if the registrar created the contact address
        if (contactHeader != null) {
            expires = contactHeader.getExpires();
        } else {
            ExpiresHeader expiresHeader = response.getExpires();
            if (expiresHeader != null) {
                expires = expiresHeader.getExpires();
            }
        }
    }
    // fix by Luca Bincoletto <Luca.Bincoletto@tilab.com>
    if (expires == 0) {
        isUnregistering = false;
        sipManCallback.fireUnregistered(address.toString());
    } else {
        if (reRegisterTimer != null)
            reRegisterTimer.cancel();
        if (keepAliveTimer != null)
            keepAliveTimer.cancel();
        reRegisterTimer = new Timer();
        keepAliveTimer = new Timer();
        // if (expires > 0 && expires < 60) {
        // [issue 2] Schedule re registrations
        // bug reported by LynlvL@netscape.com
        // use the value returned by the server to reschedule
        // registration
        SipURI uri = (SipURI) address.getURI();
        scheduleReRegistration(uri.getHost(), uri.getPort(), uri.getTransportParam(), expires);
        // }
        /*
            * else{ SipURI uri = (SipURI) address.getURI();
            * scheduleReRegistration(uri.getHost(), uri.getServerPort(),
            * uri.getTransportParam(), expires); }
            */
        sipManCallback.fireRegistered(address.toString());
    }
}
Also used : Address(javax.sip.address.Address) Timer(java.util.Timer) SipURI(javax.sip.address.SipURI)

Example 48 with Timer

use of java.util.Timer in project LoadingView by ldoublem.

the class TestActivity method startLVRingProgressAnim.

private void startLVRingProgressAnim() {
    mValueLVRingProgress = 0;
    if (mTimerLVRingProgress != null) {
        // 退出之前的mTimer
        mTimerLVRingProgress.cancel();
    }
    mTimerLVRingProgress = new Timer();
    timerTaskLVRingProgress();
}
Also used : Timer(java.util.Timer)

Example 49 with Timer

use of java.util.Timer in project head by mifos.

the class ApplicationInitializer method cancelMySQLStatement.

private void cancelMySQLStatement() {
    // mysql statement cancellation timer (mysql bug 36565)
    ClassLoader myClassLoader = this.getClass().getClassLoader();
    Class clazz;
    try {
        clazz = Class.forName("com.mysql.jdbc.ConnectionImpl", false, myClassLoader);
        if (!(clazz.getClassLoader() == myClassLoader)) {
            logger.info("MySQL ConnectionImpl was loaded with another ClassLoader: (" + clazz.getClassLoader() + "): cancelling anyway");
        } else {
            logger.info("MySQL ConnectionImpl was loaded with the WebappClassLoader: cancelling the Timer");
        }
        Field f = clazz.getDeclaredField("cancelTimer");
        f.setAccessible(true);
        Timer timer = (Timer) f.get(null);
        timer.cancel();
        logger.info("completed timer cancellation");
    } catch (ClassNotFoundException e) {
        logger.warn("failed mysql timer cancellation", e);
    } catch (SecurityException e) {
        logger.warn("failed mysql timer cancellation", e);
    } catch (NoSuchFieldException e) {
        logger.warn("failed mysql timer cancellation", e);
    } catch (IllegalArgumentException e) {
        logger.warn("failed mysql timer cancellation", e);
    } catch (IllegalAccessException e) {
        logger.warn("failed mysql timer cancellation", e);
    } catch (NullPointerException e) {
        // Expected exception, do not log NPE causee
        logger.info("No mysql timer cancellation required");
    }
}
Also used : Field(java.lang.reflect.Field) Timer(java.util.Timer)

Example 50 with Timer

use of java.util.Timer in project openhab1-addons by openhab.

the class HomematicPublisher method execute.

/**
     * Sends or delays a event to a Homematic server.
     */
public void execute(final Event event) throws HomematicClientException {
    double delay = event.getDelay();
    if (delay > 0.0) {
        synchronized (this) {
            logger.debug("Delaying event for {} seconds: {}", delay, event.getHmValueItem());
            Timer timer = delayedEvents.get(event.getBindingConfig());
            if (timer != null) {
                timer.cancel();
            }
            timer = new Timer();
            delayedEvents.put(event.getBindingConfig(), timer);
            timer.schedule(new TimerTask() {

                @Override
                public void run() {
                    try {
                        delayedEvents.remove(event.getBindingConfig());
                        sendToClient(event);
                    } catch (Exception ex) {
                        logger.error(ex.getMessage(), ex);
                    }
                }
            }, (long) (delay * 1000));
        }
    } else {
        sendToClient(event);
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) HomematicClientException(org.openhab.binding.homematic.internal.communicator.client.HomematicClientException)

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