use of com.exalttech.trex.remote.exceptions.PortAcquireException in project trex-stateless-gui by cisco-system-traffic-generator.
the class RPCMethods method acquireServerPort.
/**
*
* @param portID the port ID
* @param force if force is set to true then the port will be acquired even
* though it is owned by other
* @return connectionHandler in case of success
* @throws PortAcquireException
*/
public String acquireServerPort(int portID, boolean force) throws PortAcquireException {
LOG.trace("Acquiring port [" + portID + "]");
LogsController.getInstance().appendText(LogType.INFO, "Acquiring port [" + portID + "]");
AcquireParams acquireParams = new AcquireParams();
acquireParams.setPortId(portID);
acquireParams.setForce(force);
acquireParams.setUser(serverConnectionManager.getClientName());
acquireParams.setSessionId(Util.getRandomID());
ObjectMapper mapper = new ObjectMapper();
try {
String response = serverConnectionManager.sendRPCRequest(Constants.ACQUIRE_METHOD, acquireParams);
response = Util.removeFirstBrackets(response);
RPCResponse rpcResult = mapper.readValue(response, RPCResponse.class);
String handler = mapper.readValue(rpcResult.getResult(), String.class);
connectionHandler.put(portID, handler);
serverConnectionManager.propagatePortHandler(portID, handler);
return handler;
} catch (JsonProcessingException | UnsupportedEncodingException | InvalidRPCResponseException | IncorrectRPCMethodException | NullPointerException ex) {
throw new PortAcquireException(ex.getMessage());
} catch (IOException ex) {
throw new PortAcquireException(ex.getMessage());
}
}
use of com.exalttech.trex.remote.exceptions.PortAcquireException in project trex-stateless-gui by cisco-system-traffic-generator.
the class RPCMethods method acquireAllServerPorts.
/**
*
* @param portList
* @param force
*/
public void acquireAllServerPorts(List<Port> portList, Boolean force) {
try {
connectionHandler.clear();
for (Port port : portList) {
String handler = this.acquireServerPort(port.getIndex(), force);
connectionHandler.put(port.getIndex(), handler);
}
} catch (PortAcquireException ex) {
LOG.error("------" + ex.getMessage());
}
}
Aggregations