Package net.sf.agentopia.util

Examples of net.sf.agentopia.util.Config


        catch (IOException exc) {
            exc.printStackTrace();
        }

        // Set window size and position.
        Config conf = Config.getConfig();
        int windowWid = conf.getInt("GUI.WindowWid", 800);
        int windowHei = conf.getInt("GUI.WindowHei", 600);
        frame.setSize(windowWid, windowHei);
        int windowX = conf.getInt("GUI.WindowX", -1);
        int windowY = conf.getInt("GUI.WindowY", -1);
        if (-1 == windowX || -1 == windowY) {
            GUI.centerWindow(frame);
        }
        else {
            frame.setLocation(windowX, windowY);
View Full Code Here


        }
        frame.setVisible(false);
        frame.dispose();

        // Save all changes to the configuration.
        Config conf = Config.getConfig();
        conf.putInt("GUI.WindowWid", frame.getWidth());
        conf.putInt("GUI.WindowHei", frame.getHeight());
        conf.putInt("GUI.WindowX", frame.getX());
        conf.putInt("GUI.WindowY", frame.getY());
        conf.save();

        // Exit.
        System.exit(0);
    }
View Full Code Here

     */
    public static void updateFromInternet() {
        long startTime = new Date().getTime();
        boolean isErrorOccured = false;
        try {
            final Config conf = Config.getConfig();

            // Check if auto update is wished at all.
            final String autoUpdateActivated = conf.get("AutoUpdate.activate", "false");
            if (!autoUpdateActivated.equalsIgnoreCase("true")) {
                return;
            }

            // Make proxy settings.
            final String httpProxy = conf.get("AutoUpdate.proxy", null);
            if (null != httpProxy) {
                int dot = httpProxy.indexOf(":");
                if (-1 == dot) {
                    System.setProperty("http.proxyHost", httpProxy);
                }
                else {
                    System.setProperty("http.proxyHost", httpProxy.substring(0, dot));
                    System.setProperty("http.proxyPort", httpProxy.substring(dot + 1));
                }
            }

            // Access old jar file.
            String classPath = System.getProperty("java.class.path");
            String separator = System.getProperty("path.separator").toString().substring(0, 1);
            StringTokenizer classPathTokenizer = new StringTokenizer(classPath, separator);
            String jarFileName = null;
            while (null == jarFileName && classPathTokenizer.hasMoreTokens()) {
                jarFileName = classPathTokenizer.nextToken();
                if (-1 == jarFileName.indexOf("agentopia.jar")) {
                    jarFileName = null;
                }
            }
            if (null == jarFileName) {
                Logger.getLogger().warn("Could not find agentopia.jar in classpath. Update failed.");
                return;
            }
            DataInputStream jarIn = new DataInputStream(new FileInputStream(jarFileName));
            int jarByteCount = jarIn.available();
            if (jarByteCount <= 0) {
                Logger.getLogger().warn("Could not open agentopia.jar. Aborting.");
                return;
            }
            jarIn.close();

            // Determine internet location.
            String baseUrl = conf.get("AutoUpdate.download", DEFAULT_URL);
            if (!baseUrl.endsWith("/")) {
                baseUrl += "/";
            }

            // Read version information.
            URL versionUrl = new URL(baseUrl + "version");
            BufferedReader versionIn = new BufferedReader(new InputStreamReader(versionUrl.openStream()));
            String versionInfo = versionIn.readLine();
            String fileSizeInfo = versionIn.readLine();
            versionIn.close();
            final int currentVersion = conf.getInt("AutoUpdate.version", 0);
            final int remoteVersion = Integer.parseInt(versionInfo);
            final int remoteFileSize = Integer.parseInt(fileSizeInfo);
            if (currentVersion >= remoteVersion) {
                if (AgentopiaConstants.PERFORMANCE_DEBUG) {
                    Logger.getLogger().info("Internet auto update check took " + (System.currentTimeMillis() - startTime) + " millies.");
                }
                return;
            }

            // Read new jar file.
            URL jarUrl = new URL(baseUrl + "agentopia.jar");
            byte[] jarBytes = new byte[remoteFileSize];
            jarIn = new DataInputStream(new BufferedInputStream(jarUrl.openStream()));
            jarIn.readFully(jarBytes);
            jarIn.close();
            DataOutputStream jarOut = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(jarFileName)));
            jarOut.write(jarBytes);
            jarOut.flush();
            jarOut.close();
            conf.putInt("AutoUpdate.version", remoteVersion);

            // Say you gotta restart.
            if (GUI.isGraphicAvailable()) {
                javax.swing.JOptionPane.showMessageDialog(null, "Update complete (from version " + currentVersion + " to version " + remoteVersion + "). Please restart. Sorry for the inconvenience.");
            }
            else {
                Logger.getLogger().info("Update complete. Version is now " + remoteVersion + ".\nPlease restart. Sorry for the inconvenience.");
            }

            // Return.
            conf.save();
            System.exit(0);
        }
        catch (Exception exc) {
            isErrorOccured = true;
            Logger.getLogger().warn(exc, "Internet update had an exception.");
View Full Code Here

     * <p>
     * (1) Try to create the hosts in the config.<br>
     * (2) Use the routers from config to get their exits.
     */
    private void createExits() {
        final Config conf = getLocalConfig();
        String hostName;
        HostId hostId;

        // (1) Get all the _HOSTS_ from the config file.
        for (String hostKey : conf.keys("host")) {
            if (getExitCount() >= this.maximumExitCount) {
                break;
            }
            hostName = conf.get(hostKey, null);
            if (null != hostName) {
                try {
                    hostId = new HostId(hostName);
                    createExit(hostId);
                }
                catch (IOException exc) {
                    // Host not reachable or rejected. No problem.
                }
            }
        }

        // (2) Get all the _ROUTERS_ from config file.
        for (String routerKey : conf.keys("router")) {
            hostName = conf.get(routerKey, null);
            if (null != hostName) {
                try {
                    hostId = new HostId(hostName);
                    createExitsFromRouter(hostId);
                }
View Full Code Here

    /**
     * Creates all serviteurs as stated in the config file.
     */
    private void createServiteurs() {
        Config conf = getLocalConfig();
        IAgentopiaServiteur serviteur;

        // Go through all services in the config file.
        for (String serviceKey : conf.keys("service")) {
            String service = conf.get(serviceKey, null);
            if (null != service) {
                try {
                    serviteur = (IAgentopiaServiteur) Class.forName(service).newInstance();
                    addServiteur(serviteur);
                }
View Full Code Here

        catch (IOException exc) {
            exc.printStackTrace();
        }

        // Set window size and position.
        Config conf = Config.getConfig();
        int windowWid = conf.getInt("GUI.WindowWid", 800);
        int windowHei = conf.getInt("GUI.WindowHei", 600);
        frame.setSize(windowWid, windowHei);
        int windowX = conf.getInt("GUI.WindowX", -1);
        int windowY = conf.getInt("GUI.WindowY", -1);
        if (-1 == windowX || -1 == windowY) {
            GUI.centerWindow(frame);
        }
        else {
            frame.setLocation(windowX, windowY);
        }

        // Make sure window saves all when closing.
        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent evt) {
                shutDown();
            }
        });

        // Make window visible.
        frame.setVisible(true);

        // Signal to other config singleton clients that we have a GUI.
        conf.put("GUI.activate", "true");
        conf.save();
    }
View Full Code Here

            exc.printStackTrace();
            JOptionPane.showMessageDialog(frame, "Unable to shutdown: " + exc.getMessage());
        }

        // Save all changes to the configuration.
        Config conf = Config.getConfig();
        conf.putInt("GUI.WindowWid", frame.getWidth());
        conf.putInt("GUI.WindowHei", frame.getHeight());
        conf.putInt("GUI.WindowX", frame.getX());
        conf.putInt("GUI.WindowY", frame.getY());
        conf.save();

        // Exit.
        if (SHOW_LAST_DIALOG) {
            JOptionPane.showMessageDialog(frame, "Shutdown ok, goodbye!");
        }
View Full Code Here

TOP

Related Classes of net.sf.agentopia.util.Config

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.