/** * Receive notification of the header of a message. Parser will call * this method to report about header reading. * * @param header * the header from the message. */ public void header(String header) throws ParseException { command = new DeleteConnection(source != null ? source : stack, endpoint); command.setTransactionHandle(remoteTID); }
public String encode(JainMgcpCommandEvent event) { // encode message header Utils utils = utilsFactory.allocate(); DeleteConnection evt = (DeleteConnection) event; StringBuffer s = new StringBuffer(); s.append("DLCX ").append(evt.getTransactionHandle()).append(SINGLE_CHAR_SPACE).append( evt.getEndpointIdentifier()).append(SINGLE_CHAR_SPACE).append(MGCP_VERSION).append(NEW_LINE); // encode optional parameters if (evt.getBearerInformation() != null) { s.append("B:e:").append(evt.getBearerInformation()).append(NEW_LINE); } if (evt.getCallIdentifier() != null) { s.append("C:").append(evt.getCallIdentifier()).append(NEW_LINE); } if (evt.getConnectionIdentifier() != null) { s.append("I:").append(evt.getConnectionIdentifier()).append(NEW_LINE); } if (evt.getConnectionParms() != null) { s.append("P:").append(utils.encodeConnectionParms(evt.getConnectionParms())).append(NEW_LINE); } if (evt.getNotificationRequestParms() != null) { s.append(utils.encodeNotificationRequestParms(evt.getNotificationRequestParms())); } if (evt.getReasonCode() != null) { s.append("E:").append(evt.getReasonCode()); } utilsFactory.deallocate(utils); return s.toString(); }
/** * Receive notification of the parameter of a message. Parser will call * this method to report about parameter reading. * * @param name * the name of the paremeter * @param value * the value of the parameter. */ public void param(String name, String value) throws ParseException { if (name.equalsIgnoreCase("B")) { command.setBearerInformation(utils.decodeBearerInformation(value)); } else if (name.equalsIgnoreCase("c")) { command.setCallIdentifier(new CallIdentifier(value)); } else if (name.equalsIgnoreCase("I")) { command.setConnectionIdentifier(new ConnectionIdentifier(value)); } else if (name.equalsIgnoreCase("X")) { command.setNotificationRequestParms(new NotificationRequestParms(new RequestIdentifier(value))); } else if (name.equalsIgnoreCase("R")) { command.getNotificationRequestParms().setRequestedEvents(utils.decodeRequestedEventList(value)); } else if (name.equalsIgnoreCase("S")) { command.getNotificationRequestParms().setSignalRequests(utils.decodeEventNames(value)); } else if (name.equalsIgnoreCase("T")) { command.getNotificationRequestParms().setDetectEvents(utils.decodeEventNames(value)); } else if (name.equalsIgnoreCase("P")) { command.setConnectionParms(utils.decodeConnectionParms(value)); } else if (name.equalsIgnoreCase("E")) { command.setReasonCode(utils.decodeReasonCode(value)); } }
DeleteConnection deleteConnection = new DeleteConnection(this, mgcpEndpoint.getEndpointIdentifier()); deleteConnection.setCallIdentifier(this.getCallIdentifier()); deleteConnection.setTransactionHandle(mgcpProvider.getUniqueTransactionHandler()); mgcpProvider.sendMgcpEvents( new JainMgcpEvent[] { deleteConnection });
protected void onDestroyEndpoint(DestroyEndpoint message, ActorRef self, ActorRef sender) { if (!id.getLocalEndpointName().contains("$")) { if (!this.destroying.get()) { if (logger.isInfoEnabled()) { String msg = String.format("About to destroy endoint %s", id); logger.info(msg); } this.destroying.set(true); DeleteConnection dlcx = new DeleteConnection(self, this.id); this.gateway.tell(dlcx, self); // Make sure we don't wait forever getContext().setReceiveTimeout(Duration.create(timeout, TimeUnit.MILLISECONDS)); } } else { this.pendingDestroy.set(true); this.pendingDestroyEndpointSender = sender; this.pendingDestroyEndpointMessage = message; if (logger.isInfoEnabled()) { String msg = String.format("DestroyEndoint %s will be set to pending until previous transaction completes", id); logger.info(msg); } } }
private void deleteConnection (final Object message, final ActorRef sender) { final ActorRef self = self(); final DeleteConnection dlcx = (DeleteConnection) message; if (dlcx.getConnectionIdentifier() == null) { connEndpointMap.values().removeAll(Collections.singleton(dlcx.getEndpointIdentifier().getLocalEndpointName())); monitoringService.tell(new MgcpConnectionDeleted(null, dlcx.getEndpointIdentifier().getLocalEndpointName()), self()); monitoringService.tell(new MgcpEndpointDeleted(dlcx.getEndpointIdentifier().getLocalEndpointName()), self()); if (logger.isInfoEnabled()) { String msg = String.format("Endpoint deleted %s", dlcx.getEndpointIdentifier().getLocalEndpointName()); logger.info(msg); connEndpointMap.remove(dlcx.getConnectionIdentifier().toString()); monitoringService.tell(new MgcpConnectionDeleted(dlcx.getConnectionIdentifier().toString(), null), self()); if (!connEndpointMap.values().contains(dlcx.getEndpointIdentifier().getLocalEndpointName())) { monitoringService.tell(new MgcpEndpointDeleted(dlcx.getEndpointIdentifier().getLocalEndpointName()), self()); if (logger.isInfoEnabled()) { String msg = String.format("Endpoint deleted %s since because there are no more connections related to this endpoint", dlcx.getEndpointIdentifier().getLocalEndpointName()); logger.info(msg); System.out.println(dlcx.toString()); final ReturnCode code = ReturnCode.Transaction_Executed_Normally; final DeleteConnectionResponse response = new DeleteConnectionResponse(self, code); final int transaction = dlcx.getTransactionHandle(); response.setTransactionHandle(transaction); System.out.println(response.toString());
return; case SuccessResponse: if (this.endpointId.equals(dcRequest.getEndpointIdentifier().toString())) { if (dcRequest.getNotificationRequestParms() != null) { processRequestedEvents(null, dcRequest.getNotificationRequestParms().getRequestedEvents()); if (dcRequest.getConnectionIdentifier() != null) { this.connectionIds.remove(dcRequest.getConnectionIdentifier()); if (logger.isDebugEnabled()) { logger.debug("Removing connection:" + dcRequest.getConnectionIdentifier() + " From:" + Arrays.toString(this.connectionIds.toArray()) + " ------ " + this);
@Override public void execute(final Object message) throws Exception { final String sessionId = Integer.toString(session.id()); final CallIdentifier callId = new CallIdentifier(sessionId); final DeleteConnection dlcx = new DeleteConnection(source, callId, endpointId, connId); gateway.tell(dlcx, source); // Make sure we don't wait for a response indefinitely. getContext().setReceiveTimeout(Duration.create(timeout, TimeUnit.MILLISECONDS)); } }
public JainMgcpCommandEvent decodeCommand(byte[] data,SplitDetails[] message) throws ParseException { command = new DeleteConnection(source != null ? source : stack, endpoint); command.setTransactionHandle(remoteTID); try { (new CommandContentHandle()).parse(data,message); } catch (IOException e) { logger.error("Decode of DLCX command failed", e); } return command; }
totalLength+=StringFunctions.encodeInt(array,5,event.getTransactionHandle()); array[totalLength++]=StringFunctions.SPACE_BYTE; totalLength+=EndpointIdentifierHandler.encode(array,totalLength,evt.getEndpointIdentifier()); array[totalLength++]=StringFunctions.SPACE_BYTE; System.arraycopy(MGCP_VERSION, 0, array, totalLength, MGCP_VERSION.length); if (evt.getBearerInformation() != null) totalLength+=BearerInformationHandler.encode(array,totalLength,evt.getBearerInformation()); array[totalLength++]=StringFunctions.NEWLINE_BYTE; if (evt.getCallIdentifier() != null) { array[totalLength++]=StringFunctions.HIGH_C_BYTE; array[totalLength++]=StringFunctions.COLON_BYTE; byte[] callBytes=evt.getCallIdentifier().toString().getBytes(); System.arraycopy(callBytes, 0, array,totalLength, callBytes.length); totalLength+=callBytes.length; if (evt.getConnectionIdentifier() != null) byte[] connectionIdentifierBytes=evt.getConnectionIdentifier().toString().getBytes(); System.arraycopy(connectionIdentifierBytes, 0, array,totalLength, connectionIdentifierBytes.length); totalLength+=connectionIdentifierBytes.length; if (evt.getConnectionParms() != null) totalLength+=ConnectionParmHandler.encodeList(array,totalLength,evt.getConnectionParms()); array[totalLength++]=StringFunctions.NEWLINE_BYTE;
command.setBearerInformation(BearerInformationHandler.decode(data,value.getOffset(),value.getLength())); break; case StringFunctions.LOW_C_BYTE: case StringFunctions.HIGH_C_BYTE: command.setCallIdentifier(new CallIdentifier(new String(data,value.getOffset(),value.getLength()))); break; case StringFunctions.LOW_I_BYTE: case StringFunctions.HIGH_I_BYTE: command.setConnectionIdentifier(new ConnectionIdentifier(new String(data,value.getOffset(),value.getLength()))); break; case StringFunctions.LOW_X_BYTE: case StringFunctions.HIGH_X_BYTE: command.setNotificationRequestParms(new NotificationRequestParms(new RequestIdentifier(new String(data,value.getOffset(),value.getLength())))); break; case StringFunctions.LOW_R_BYTE: case StringFunctions.HIGH_R_BYTE: command.getNotificationRequestParms().setRequestedEvents(RequestedEventHandler.decodeList(data,value.getOffset(),value.getLength())); break; case StringFunctions.LOW_S_BYTE: case StringFunctions.HIGH_S_BYTE: command.getNotificationRequestParms().setSignalRequests(EventNameHandler.decodeList(data,value.getOffset(),value.getLength())); break; case StringFunctions.LOW_T_BYTE: case StringFunctions.HIGH_T_BYTE: command.getNotificationRequestParms().setDetectEvents(EventNameHandler.decodeList(data,value.getOffset(),value.getLength())); break; case StringFunctions.LOW_P_BYTE: case StringFunctions.HIGH_P_BYTE: command.setConnectionParms(ConnectionParmHandler.decodeList(data,value.getOffset(),value.getLength()));
@Override public void execute(final Object message) throws Exception { final String sessionId = Integer.toString(session.id()); final CallIdentifier callId = new CallIdentifier(sessionId); final DeleteConnection dlcx = new DeleteConnection(source, callId, primaryEndpointId, primaryConnId); gateway.tell(dlcx, source); // Make sure we don't wait for a response indefinitely. getContext().setReceiveTimeout(Duration.create(timeout, TimeUnit.MILLISECONDS)); } }
public JainMgcpCommandEvent decodeCommand(byte[] data,SplitDetails[] message) throws ParseException { command = new DeleteConnection(source != null ? source : stack, endpoint); command.setTransactionHandle(remoteTID); try { (new CommandContentHandle()).parse(data,message); } catch (IOException e) { logger.error("Decode of DLCX command failed", e); } return command; }
totalLength+=StringFunctions.encodeInt(array,5,event.getTransactionHandle()); array[totalLength++]=StringFunctions.SPACE_BYTE; totalLength+=EndpointIdentifierHandler.encode(array,totalLength,evt.getEndpointIdentifier()); array[totalLength++]=StringFunctions.SPACE_BYTE; System.arraycopy(MGCP_VERSION, 0, array, totalLength, MGCP_VERSION.length); if (evt.getBearerInformation() != null) totalLength+=BearerInformationHandler.encode(array,totalLength,evt.getBearerInformation()); array[totalLength++]=StringFunctions.NEWLINE_BYTE; if (evt.getCallIdentifier() != null) { array[totalLength++]=StringFunctions.HIGH_C_BYTE; array[totalLength++]=StringFunctions.COLON_BYTE; byte[] callBytes=evt.getCallIdentifier().toString().getBytes(); System.arraycopy(callBytes, 0, array,totalLength, callBytes.length); totalLength+=callBytes.length; if (evt.getConnectionIdentifier() != null) byte[] connectionIdentifierBytes=evt.getConnectionIdentifier().toString().getBytes(); System.arraycopy(connectionIdentifierBytes, 0, array,totalLength, connectionIdentifierBytes.length); totalLength+=connectionIdentifierBytes.length; if (evt.getConnectionParms() != null) totalLength+=ConnectionParmHandler.encodeList(array,totalLength,evt.getConnectionParms()); array[totalLength++]=StringFunctions.NEWLINE_BYTE;
command.setBearerInformation(BearerInformationHandler.decode(data,value.getOffset(),value.getLength())); break; case StringFunctions.LOW_C_BYTE: case StringFunctions.HIGH_C_BYTE: command.setCallIdentifier(new CallIdentifier(new String(data,value.getOffset(),value.getLength()))); break; case StringFunctions.LOW_I_BYTE: case StringFunctions.HIGH_I_BYTE: command.setConnectionIdentifier(new ConnectionIdentifier(new String(data,value.getOffset(),value.getLength()))); break; case StringFunctions.LOW_X_BYTE: case StringFunctions.HIGH_X_BYTE: command.setNotificationRequestParms(new NotificationRequestParms(new RequestIdentifier(new String(data,value.getOffset(),value.getLength())))); break; case StringFunctions.LOW_R_BYTE: case StringFunctions.HIGH_R_BYTE: command.getNotificationRequestParms().setRequestedEvents(RequestedEventHandler.decodeList(data,value.getOffset(),value.getLength())); break; case StringFunctions.LOW_S_BYTE: case StringFunctions.HIGH_S_BYTE: command.getNotificationRequestParms().setSignalRequests(EventNameHandler.decodeList(data,value.getOffset(),value.getLength())); break; case StringFunctions.LOW_T_BYTE: case StringFunctions.HIGH_T_BYTE: command.getNotificationRequestParms().setDetectEvents(EventNameHandler.decodeList(data,value.getOffset(),value.getLength())); break; case StringFunctions.LOW_P_BYTE: case StringFunctions.HIGH_P_BYTE: command.setConnectionParms(ConnectionParmHandler.decodeList(data,value.getOffset(),value.getLength()));
@Override public void execute(final Object message) throws Exception { final String sessionId = Integer.toString(session.id()); final CallIdentifier callId = new CallIdentifier(sessionId); final DeleteConnection dlcx = new DeleteConnection(source, callId, endpointId, connId); gateway.tell(dlcx, source); // Make sure we don't wait for a response indefinitely. getContext().setReceiveTimeout(Duration.create(timeout, TimeUnit.MILLISECONDS)); } }
public void onCallTerminated(RequestEvent evt, ActivityContextInterface aci) { try { MgcpConnectionActivity activity = getMgcpConnectionActivity(); DeleteConnection deleteConnection = new DeleteConnection(this, activity.getEndpointIdentifier()); deleteConnection.setTransactionHandle(mgcpProvider.getUniqueTransactionHandler()); mgcpProvider.sendMgcpEvents(new JainMgcpEvent[] { deleteConnection }); ServerTransaction tx = evt.getServerTransaction(); Request request = evt.getRequest(); Response response = messageFactory.createResponse(Response.OK, request); tx.sendResponse(response); cancelTimer(); } catch (Exception e) { logger.severe("Error while sending OK for BYE", e); } }
@Override public void execute(final Object message) throws Exception { /* Stop the timer here. */ final UntypedActorContext context = getContext(); context.setReceiveTimeout(Duration.Undefined()); final String sessionId = Integer.toString(session.id()); final CallIdentifier callId = new CallIdentifier(sessionId); final DeleteConnection dlcx = new DeleteConnection(source, callId, secondaryEndpointId, secondaryConnId); gateway.tell(dlcx, source); // Make sure we don't wait for a response indefinitely. getContext().setReceiveTimeout(Duration.create(timeout, TimeUnit.MILLISECONDS)); } }
public void onCallTerminated(RequestEvent evt, ActivityContextInterface aci) { EndpointIdentifier endpointID = new EndpointIdentifier(this.getEndpointName(), JBOSS_BIND_ADDRESS + ":" + MGCP_PEER_PORT); DeleteConnection deleteConnection = new DeleteConnection(this, endpointID); deleteConnection.setTransactionHandle(mgcpProvider.getUniqueTransactionHandler()); mgcpProvider.sendMgcpEvents(new JainMgcpEvent[] { deleteConnection }); ServerTransaction tx = evt.getServerTransaction(); Request request = evt.getRequest(); try { Response response = messageFactory.createResponse(Response.OK, request); tx.sendResponse(response); } catch (Exception e) { logger.severe("Error while sending DLCX ", e); } }
public void disconnect() throws MgcpConnectionException { final State state = getState(); if(HALF_OPEN.equals(state) || OPEN.equals(state)) { try { final CallIdentifier callId = new CallIdentifier(Integer.toString(session.getId())); final DeleteConnection dlcx = new DeleteConnection(this, callId, endpoint.getId(), connectionId); server.sendCommand(dlcx, this); setState(DISCONNECTED); } catch(final MgcpServerException exception) { setState(FAILED); fireFailed(); throw new MgcpConnectionException(exception); } } }