use of com.cosylab.acs.maci.ClientInfo in project ACS by ACS-Community.
the class ManagerImpl method getClients.
/**
* Get client info. for specified handles of <code>Client</code> or <code>Administrator</code>. For <code>Component</code>
* handles component's <code>Container</code> is returned.
*
* @param excludeHandle handle of client not to be included in the array, can be 0.
* @param handles handles of the clients whose info. should be returned, non-<code>null</code>.
* @param returns requested infos, <code>null</code> if none
*/
private ClientInfo[] getClients(int excludeHandle, int[] handles) {
assert (handles != null);
// array of clients to be notified
ClientInfo[] clients = null;
ArrayList<ClientInfo> list = new ArrayList<ClientInfo>();
for (int i = 0; i < handles.length; i++) if (handles[i] != excludeHandle) {
if ((handles[i] & TYPE_MASK) == COMPONENT_MASK) {
ComponentInfo componentInfo = getComponentInfo(handles[i]);
if (componentInfo != null) {
ContainerInfo containerInfo = getContainerInfo(componentInfo.getContainer());
if (containerInfo != null) {
ClientInfo info = new ClientInfo(containerInfo.getHandle(), containerInfo.getName(), containerInfo.getContainer());
list.add(info);
}
}
} else {
ClientInfo info = getClientInfo(handles[i]);
if (info != null)
list.add(info);
}
}
// copy to array
if (list.size() > 0) {
clients = new ClientInfo[list.size()];
list.toArray(clients);
}
return clients;
}
use of com.cosylab.acs.maci.ClientInfo in project ACS by ACS-Community.
the class ManagerImpl method getClientInfo.
/**
* @see com.cosylab.acs.maci.Manager#getClientInfo(int, int[], String)
*/
public ClientInfo[] getClientInfo(int id, int[] handles, String name_wc) throws AcsJNoPermissionEx {
if (handles == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'handles' sequence expected.");
throw af;
} else if (handles.length == 0 && name_wc == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'names_wc' sequence expected.");
throw af;
}
/*
Pattern pattern = null;
if (handles.length == 0 && name_wc != null)
{
// test wildcard patten (try to compile it)
try
{
pattern = Pattern.compile(name_wc);
}
catch (Exception ex)
{
// BAD_PARAM
BadParametersException af = new BadParametersException("Failed to compile 'names_wc' reqular expression string '"+name_wc+"'.");
af.caughtIn(this, "getClientInfo");
af.putValue("name_wc", name_wc);
throw af;
}
}
*/
/****************************************************************/
// info to be returned
ClientInfo[] info = null;
// requesting info. about itself
if (handles.length == 1 && handles[0] == id) {
// check handle, no special rights for own info
securityCheck(id, 0);
info = new ClientInfo[1];
info[0] = getClientInfo(id);
} else // get info of requested handles
if (handles.length > 0) {
// check handle, INTROSPECT_MANAGER rights needed
securityCheck(id, AccessRights.INTROSPECT_MANAGER);
info = new ClientInfo[handles.length];
for (int i = 0; i < handles.length; i++) info[i] = getClientInfo(handles[i]);
} else // get info requested using name wildcard
{
// check handle, INTROSPECT_MANAGER rights needed
securityCheck(id, AccessRights.INTROSPECT_MANAGER);
// list of clients matching search pattern
ArrayList<ClientInfo> list = new ArrayList<ClientInfo>();
// check clients
synchronized (clients) {
int h = clients.first();
while (h != 0) {
ClientInfo clientInfo = (ClientInfo) clients.get(h);
/*
Matcher m = pattern.matcher(clientInfo.getName());
if (m.matches())
*/
if (WildcharMatcher.match(name_wc, clientInfo.getName()))
list.add(clientInfo);
h = clients.next(h);
}
}
// check administrators
synchronized (administrators) {
int h = administrators.first();
while (h != 0) {
ClientInfo clientInfo = (ClientInfo) administrators.get(h);
/*
Matcher m = pattern.matcher(clientInfo.getName());
if (m.matches())
*/
if (WildcharMatcher.match(name_wc, clientInfo.getName()))
list.add(clientInfo);
h = administrators.next(h);
}
}
// copy to array
info = new ClientInfo[list.size()];
list.toArray(info);
}
return info;
}
use of com.cosylab.acs.maci.ClientInfo 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;
}
use of com.cosylab.acs.maci.ClientInfo in project ACS by ACS-Community.
the class ManagerImpl method login.
/**
* @see com.cosylab.acs.maci.Manager#login(Client)
*/
public ClientInfo login(Client reference) throws AcsJNoPermissionEx {
// check if already shutdown
if (shutdown.get()) {
// already shutdown
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Manager in shutdown state.");
throw npe;
}
if (reference == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'reference' expected.");
throw af;
}
/****************************************************************/
ClientInfo info = null;
try {
long executionId = generateExecutionId();
AuthenticationData reply = reference.authenticate(executionId, "Identify yourself");
if (reply == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid response to 'Client::authenticate()' method - non-null structure expected.");
throw af;
} else if (reply.getClientType() == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid response to 'Client::authenticate()' method - non-null client type expected.");
throw af;
} else if (reply.getImplLang() == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid response to 'Client::authenticate()' method - no-null implementation language expected.");
throw af;
}
// get client's name
String name = reference.name();
if (name == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid response to 'Client::name()' method - non-null string expected.");
throw af;
}
logger.log(Level.FINE, "'" + name + "' is logging in.");
final long timeStamp = reply.getTimeStamp() > 0 ? reply.getTimeStamp() : System.currentTimeMillis();
if (reply.getExecutionId() != 0)
executionId = generateExecutionId();
// delegate
switch(reply.getClientType()) {
// container
case CONTAINER:
if (reference instanceof Container) {
info = containerLogin(name, reply, (Container) reference, timeStamp, executionId);
} else {
// NO_PERMISSION
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Given reply to 'Client::authenticate()' method indicated container login, but given reference does not implement 'maci::Container' interface.");
npe.setID(name);
throw npe;
}
break;
// client
case CLIENT:
info = clientLogin(name, reply, reference, timeStamp, executionId);
break;
// supervisor (administrator)
case ADMINISTRATOR:
if (reference instanceof Administrator) {
info = administratorLogin(name, reply, (Administrator) reference, timeStamp, executionId);
} else {
// NO_PERMISSION
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Given reply to 'Client::authenticate()' method indicated administrator login, but given reference does not implement 'maci::Administrator' interface.");
npe.setID(name);
throw npe;
}
break;
default:
assert (false);
}
} catch (AcsJNoPermissionEx npe) {
throw npe;
} catch (BadParametersException bpe) {
throw bpe;
} catch (NoResourcesException nre) {
throw nre;
} catch (RemoteException re) {
// TODO @todo exception
RuntimeException rt = new RuntimeException("Exception caught while examining the client. Login rejected.", re);
throw rt;
} catch (Throwable ex) {
// TODO @todo exception
RuntimeException rt = new RuntimeException("Unexpected exception during login. Login rejected.", ex);
throw rt;
}
/****************************************************************/
logger.log(Level.FINE, "Client with handle '" + HandleHelper.toString(info.getHandle()) + "' has logged in.");
return info;
}
use of com.cosylab.acs.maci.ClientInfo in project ACS by ACS-Community.
the class ManagerImpl method initializePingTasks.
/**
* Initialized (registers) all ping tasks (to completely recover).
*/
private void initializePingTasks() {
// go through all the containers, clients, administrators and register ping tasks,
// reference of classes are already in TimerTaskContainerInfo/TimerTaskClientInfo
// TODO some admin references can be null !!!
// containers
TimerTaskContainerInfo containerInfo = null;
int h = containers.first();
while (h != 0) {
containerInfo = (TimerTaskContainerInfo) containers.get(h);
h = containers.next(h);
// if deserialization failed, logout container
ClientInfo clientInfo = containerInfo.createClientInfo();
// register container to the heartbeat manager
PingTimerTask task = new PingTimerTask(this, logger, clientInfo, alarmSource);
containerInfo.setTask(task);
heartbeatTask.schedule(task, 0, containerInfo.getPingInterval());
}
// administrators
TimerTaskClientInfo adminInfo = null;
h = administrators.first();
while (h != 0) {
adminInfo = (TimerTaskClientInfo) administrators.get(h);
h = administrators.next(h);
// register administrator to the heartbeat manager
PingTimerTask task = new PingTimerTask(this, logger, adminInfo, null);
adminInfo.setTask(task);
heartbeatTask.schedule(task, 0, administratorPingInterval);
}
// clients
TimerTaskClientInfo clientInfo = null;
h = clients.first();
while (h != 0) {
clientInfo = (TimerTaskClientInfo) clients.get(h);
h = clients.next(h);
// register client to the heartbeat manager
PingTimerTask task = new PingTimerTask(this, logger, clientInfo, null);
clientInfo.setTask(task);
heartbeatTask.schedule(task, 0, clientPingInterval);
}
}
Aggregations