private static NetAction getAction(Atom atom) { NetAction.ActionType actionType = translate(atom.Action.Action_type); NetAction action = new NetAction( actionType ); switch(actionType) { case NetAction.ActionType.ACCEPTED: action.AcceptedMessage =getAcceptedMessage(atom) ; break; case NetAction.ActionType.NOTIFICATION: action.NotificationMessage = getNotificationMessage(atom) ; break; case NetAction.ActionType.FAULT: action.FaultMessage = getFaultMessage(atom) ; break; case NetAction.ActionType.PONG: action.PongMessage = getPongMessage(atom); break; default: throw new Exception("Unexpected ActionType while unmarshalling message " + actionType.ToString() ); } return action; }
public static NetMessage translate(Atom message) { NetAction action = getAction(message); IDictionary<string, string> headers = getHeaders(message); NetMessage netMessage = new NetMessage(action, headers); return netMessage; }
public static Atom translate(NetMessage message) { Atom atom = new Atom(); Action action = getAction(message); Header header = getHeaders(message); atom.Action = action; atom.Header = header; return atom; }
public NetMessage Unmarshall(byte[] data) { try{ Stream stream = new MemoryStream(data); TProtocol tProtocol = new TBinaryProtocol(new TStreamTransport(stream, stream)); Atom message = new Atom(); message.Read(tProtocol); NetMessage netMsg = ThriftMessageConverter.translate(message); return netMsg; }catch(Exception ex){ log.Error("Error unmarshalling message", ex); } return null; }
private static NetAccepted getAcceptedMessage(Atom atom) { NetAccepted accept = new NetAccepted(atom.Action.Accepted.Action_id); return accept; }
private static NetPong getPongMessage(Atom atom) { NetPong pong = new NetPong(atom.Action.Pong.Action_id); return pong; }
private static NetNotification getNotificationMessage(Atom atom) { NetNotification notification = new NetNotification(atom.Action.Notification.Destination, translate(atom.Action.Notification.Destination_type), getBrokerMessage( atom.Action.Notification.Message ), atom.Action.Notification.Subscription, atom.Header.Parameters); return notification; }
private static IDictionary<string, string> getHeaders(Atom message) { return message.Header.Parameters; }
private static NetFault getFaultMessage(Atom atom) { NetFault fault = new NetFault(atom.Action.Fault.Fault_code, atom.Action.Fault.Fault_message); fault.ActionId = atom.Action.Fault.Action_id; fault.Detail = atom.Action.Fault.Fault_detail; return fault; }