Package org.jayasoft.woj.common.model

Examples of org.jayasoft.woj.common.model.Server


                // local server should always be in database, so that it can be safely used as FK for modules per server data
                WOJServer.getInstance().getDataService().getServerDao().insert(_localServer);
            }
            if (servers != null) {
                for (Iterator iter = servers.iterator(); iter.hasNext();) {
                    Server server = (Server)iter.next();
                    if (server.getId() != _localServer.getId()) {
                        ServerState serverState = new ServerState(server);
                        _knownServers.put(server, serverState);
                    }
                }
            }
View Full Code Here


            }
        }
    }

    public void check() {
        Server master = getCurrentMaster();
        if (!_localServer.equals(master)) { // check with a copy to avoid staled state
            if (master == null) {
                LOGGER.info("no master known to be checked: starting election...");
                election();
            } else {
                LOGGER.info("checking master: "+master);
                if (ServerServicesProvider.get(master).getServerManagementService().ping()) {
                    LOGGER.info("master is still alive: "+master);
                } else {
                    LOGGER.info("master is down: "+master+". Starting election...");
                    election(getHigherServers());
                }
            }
        } else {
            // we are the master, we should check known servers state
            LOGGER.info("checking known servers state among: "+_knownServers.values());
            for (Iterator iter = getKnownServers().iterator(); iter.hasNext();) {
                Server server = (Server)iter.next();
                if (ServerServicesProvider.get(server).getServerManagementService().ping()) {
                    markServerUp(server);
                    try {
                        Server m = ServerServicesProvider.get(server).getServerManagementService().getMaster();
                        if (_master != null && !_master.equals(m) && m!=null) {
                            LOGGER.debug("another server is not in sync with what we think is the master: proceed to election");
                            if (m.getId() < _localServer.getId()) {
                                election(getHigherServers());
                            } else {
                                election();
                            }
                            return;
View Full Code Here

    private Map getHigherServersMap(Server server) {
        synchronized (_knownServers) {
            Map servers = new LinkedHashMap(_knownServers);
            for (Iterator iter = servers.keySet().iterator(); iter.hasNext();) {
                Server s = (Server)iter.next();
                if (s.getId() >= server.getId()) {
                    iter.remove();
                }
            }
            return servers;
        }
View Full Code Here

     * Returns all known servers with an id greater than our own id
     */
    private List getLowerServers() {
        List servers = getKnownServers();
        for (Iterator iter = servers.iterator(); iter.hasNext();) {
            Server server = (Server)iter.next();
            if (server.getId() <= _localServer.getId()) {
                iter.remove();
            }
        }
        return servers;
    }
View Full Code Here

        }
    }

    private void saveServers(Collection knownServers) {
        for (Iterator iter = knownServers.iterator(); iter.hasNext();) {
            Server server = (Server) iter.next();
            WOJServer.getInstance().getDataService().getServerDao().update(server);
        }
    }
View Full Code Here

    public synchronized void newPrivateKey() {
        newPrivateKey(true);
    }

    private synchronized void newPrivateKey(boolean broadcast) {
        Server master = getCurrentMaster();
        if (_localServer.equals(master)) {
            LOGGER.info("generating new private key: old was "+_keyProvider.getCurrentKey());
            _keyProvider.newKey();
            LOGGER.info("new private key: "+_keyProvider.getCurrentKey());
            if (broadcast) {
View Full Code Here

    private void broadcastPrivateKey(final Key key) {
        new Thread("broadcast-PK-"+_localServer.getId()) {
            public void run() {
                LOGGER.info("starting private key broadcast: "+key);
                for (Iterator iter = getKnownServers().iterator(); iter.hasNext();) {
                    Server server = (Server)iter.next();
                    try {
                        ServerServicesProvider.get(server).getServerManagementService().notifyNewPrivateKey(key);
                    } catch (ServiceException e) {
                        LOGGER.info("problem occured while notifying new private key to "+server, e);
                    }
View Full Code Here

        broadcastMaster();
    }

    private void broadcastMaster() {
        for (Iterator iter = getKnownServers().iterator(); iter.hasNext();) {
            Server server = (Server)iter.next();
            try {
                synchronized (this) {
                    if (!isMaster()) {
                        LOGGER.info("we have been replaced by another master during our notification of being master: new master "+getCurrentMaster());
                        return;
View Full Code Here

            setEnabled(false);
            if (isMaster()) {
                setMaster(null, false);
                LOGGER.debug("we were master, searching for a new master...");
                for (Iterator iter = getKnownServers().iterator(); iter.hasNext();) {
                    Server server = (Server)iter.next();
                    try {
                        if (ServerServicesProvider.get(server).getServerManagementService().ping()) {
                            LOGGER.debug("electing "+server+" as new master");
                            elect(server);
                            return;
View Full Code Here

            setMaster(null, false);
        }
        try {
            // first we query all servers to know who is the current master
            for (Iterator iter = serversToQuery.iterator(); iter.hasNext();) {
                Server server = (Server)iter.next();
                LOGGER.debug("querying "+server);
                Server master = null;
                try {
                    master = ServerServicesProvider.get(server).getServerManagementService().getMaster();
                } catch (Exception ex) {
                    LOGGER.debug("a problem occured while querying "+server+" to know the master: ignoring");
                    continue;
                }
                synchronized (this) {
                    if (_master != null) {
                        LOGGER.info("a new master has been elected during our own election process: "+_master);
                        return;
                    }
                }
                try {
                    if (master != null) {
                        if (master.getId() < _localServer.getId()) {
                            if (!master.equals(server)) {
                                LOGGER.debug("master found wasn't previously queried: "+master);
                                if (ServerServicesProvider.get(master).getServerManagementService().ping()) {
                                    LOGGER.debug("it seems that we didn't know master before, but it is up, we can synchronize with it: "+master);
                                    syncAndRegister(master);
                                    return;
                                } else {
                                    LOGGER.debug(master+" is down, electing "+server);
                                    markServerDown(server);
                                    elect(server);
                                    return;
                                }
                            } else {
                                LOGGER.info("found master: "+master);
                                syncAndRegister(master);
                                return;
                            }
                        } else if (server.getId() < _localServer.getId()) {
                            LOGGER.warn("a higher server ("+server+") thought that the master was a lower one: "+master);
                            LOGGER.info("electing "+server);
                            elect(server);
                            return;
                        } else if (master.getId() == _localServer.getId()) {
                            LOGGER.debug("another server already thought we were the master, we just take our place back");
                        } else {
                            LOGGER.debug("a lower server was the master, we take its place: "+master);
                            replaceMaster(master);
                            return;
View Full Code Here

TOP

Related Classes of org.jayasoft.woj.common.model.Server

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.