Search in sources :

Example 1 with AdministratorCommandAllocate

use of com.cosylab.acs.maci.manager.recovery.AdministratorCommandAllocate in project ACS by ACS-Community.

the class ManagerImpl method administratorLogin.

/**
	 * Administrator specific login method.
	 * @param	name	name of the administrator
	 * @param	reply	reply to authenticate method
	 * @param	administrator	administrator that is logging in
	 * @return	ClientInfo	client info. of newly logged administrator
	 */
private ClientInfo administratorLogin(String name, AuthenticationData reply, Administrator administrator, long timeStamp, long executionId) throws AcsJNoPermissionEx {
    assert (name != null);
    assert (administrator != null);
    TimerTaskClientInfo clientInfo = null;
    synchronized (administrators) {
        // check if administrator is already logged in,
        // if it is, return existing info
        int h = administrators.first();
        while (h != 0) {
            ClientInfo loggedAdministratorInfo = (ClientInfo) administrators.get(h);
            if (administrator.equals(loggedAdministratorInfo.getClient()))
                return loggedAdministratorInfo;
            h = administrators.next(h);
        }
        // allocate new handle
        // !!! ACID 2
        Integer objHandle = (Integer) executeCommand(new AdministratorCommandAllocate());
        int handle;
        //int handle = administrators.allocate();
        if (objHandle == null || (handle = objHandle.intValue()) == 0) {
            NoResourcesException af = new NoResourcesException("Generation of new handle failed, too many administrators logged in.");
            throw af;
        }
        // generate external handle
        h = handle | ADMINISTRATOR_MASK;
        // add generated key
        h |= (random.nextInt(0x100)) << 16;
        // create new client info
        clientInfo = new TimerTaskClientInfo(h, name, administrator);
        clientInfo.setAccessRights(AccessRights.REGISTER_COMPONENT | AccessRights.INTROSPECT_MANAGER | AccessRights.SHUTDOWN_SYSTEM);
        // register administrator to the heartbeat manager
        PingTimerTask task = new PingTimerTask(this, logger, clientInfo, null);
        clientInfo.setTask(task);
        heartbeatTask.schedule(task, administratorPingInterval, administratorPingInterval);
        // !!! ACID - register AddAdministratorCommand
        executeCommand(new AdministratorCommandSet(handle, clientInfo));
    // store info
    //administrators.set(handle, clientInfo);
    }
    // notify administrators about the login
    notifyClientLogin(clientInfo, timeStamp, executionId);
    logger.log(Level.INFO, "Administrator '" + name + "' logged in.");
    return clientInfo;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AdministratorCommandAllocate(com.cosylab.acs.maci.manager.recovery.AdministratorCommandAllocate) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) AdministratorCommandSet(com.cosylab.acs.maci.manager.recovery.AdministratorCommandSet) ClientInfo(com.cosylab.acs.maci.ClientInfo)

Aggregations

ClientInfo (com.cosylab.acs.maci.ClientInfo)1 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)1 AdministratorCommandAllocate (com.cosylab.acs.maci.manager.recovery.AdministratorCommandAllocate)1 AdministratorCommandSet (com.cosylab.acs.maci.manager.recovery.AdministratorCommandSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1