public static Message create(Message.MessageType type) { switch (type) { case Message.MessageType.RESTORE_INCENTIVE: return new RBD.Restore.Msg.RestoreIncentive(); case Message.MessageType.RESTORE_ACK: return new RBD.Restore.Msg.RestoreAck(); case Message.MessageType.RESTORE_NACK: return new RBD.Restore.Msg.RestoreNack(); case Message.MessageType.RESTORE_TABLELIST: return new RBD.Restore.Msg.RestoreTableList(); case Message.MessageType.RESTORE_TABLE: return new RBD.Restore.Msg.RestoreTable(); case Message.MessageType.TPC_ABORT: return new RBD.TPC.Msg.AbortMessage(); case Message.MessageType.TPC_PRECOMMIT: return new RBD.TPC.Msg.PreCommitMessage(); case Message.MessageType.TPC_ACKPRECOMMIT: return new RBD.TPC.Msg.AckPreCommitMessage(); case Message.MessageType.TPC_CANCOMMIT: return new RBD.TPC.Msg.PreCommitMessage(); case Message.MessageType.TPC_YESFORCOMMIT: return new RBD.TPC.Msg.YesForCommitMessage(); case Message.MessageType.TPC_DOCOMMIT: return new RBD.TPC.Msg.DoCommitMessage(); case Message.MessageType.TPC_HAVECOMMITED: return new RBD.TPC.Msg.HaveCommittedMessage(); case Message.MessageType.TPC_NOFORCOMMIT: return new RBD.TPC.Msg.NoForCommitMessage(); case Message.MessageType.TPC_ERROR: return new RBD.TPC.Msg.ErrorMessage(); case Message.MessageType.TRANSACTION_MESSAGE: return new RBD.TPC.Msg.TransactionMessage(); case Message.MessageType.CLIENT_SUCCESS: return new RBD.Msg.Client.SuccessMessage(); case Message.MessageType.CLIENT_CONFLICT: return new RBD.Msg.Client.ConflictMessage(); case Message.MessageType.CLIENT_ERROR: return new RBD.Msg.Client.ErrorMessage(); case Message.MessageType.CLIENT_RESULTSET: return new RBD.Msg.Client.ResultsetMessage(); case Message.MessageType.CLIENT_TIMEOUT: return new RBD.Msg.Client.TimeoutMessage(); case Message.MessageType.HELLO_MESSAGE: return new RBD.Msg.HelloMessage(); } Logger.getInstance().log("Unknown message type", LOGGING_NAME, Logger.Level.SEVERE); return null; }
/** * Metoda wywolywana, gdy transakcja zostala zakonczona niepomyslnie. */ public void abortTransaction(Message messageToClient) { broadcastMessage(new AbortMessage()); TcpSender.getInstance().sendToNode(messageToClient, getClientAddress()); setState(new AbortState()); endTransaction(); }
//throws InterruptedException public void brainsplit(Message msg) { lock (this) { // current transaction can timeout if (msg is CanCommitMessage) { // forbid new transactions Logger.getInstance().log( "Sending message to blocked cohort: " + msg.toString(), LOGGING_NAME, Logger.Level.INFO); blockedCohort.putMessage(msg); } else if (msg is TransactionMessage) { // forbid new transactions Logger.getInstance().log( "Sending message to blocked coordinator: " + msg.toString(), LOGGING_NAME, Logger.Level.INFO); blockedCoordinator.putMessage(msg); } else if (msg is RestoreIncentive) { // forbid new restoration Logger.getInstance().log( "Sending message to blocked restore coordinator: " + msg.toString(), LOGGING_NAME, Logger.Level.INFO); blockedRestoreCoordinator.putMessage(msg); } else if (msg is HelloMessage) { HelloMessage hm = (HelloMessage)msg; IPEndPoint node = new IPEndPoint( hm.getSender().Address, hm.ListeningPort ); if (node.Equals(me)) return; // try to add new node TcpSender.getInstance().AddServerNode(node, queue); } else { Logger.getInstance().log( "Undelivered message due to brainsplit: " + msg.toString(), LOGGING_NAME, Logger.Level.WARNING); } } }
protected override void onNewMessage(Message message) { if (message is CanCommitMessage) { onCanCommit((CanCommitMessage) message); } else if (message is AbortMessage) { onAbort(); } else if (message is DoCommitMessage) { onDoCommit(); } else if (message is PreCommitMessage) { onPreCommit(); } else if(message is TimeoutMessage) { state.onTimeout(); } }
public void sendToAll(Message msg) { lock (this) { try { byte[] data = msg.Serialize(); socket.Send(data); //Logger.getInstance().log("Sending: [" + msg.ToString() + "]", LOGGING_NAME, Logger.Level.INFO); } catch (SocketException ex) { Logger.getInstance().log("SocketException: " + ex.Message, LOGGING_NAME, Logger.Level.WARNING); } } }
//throws InterruptedException, TimeoutException public Message accept(Message.MessageType[] types, IPEndPoint node) { while (true) { Message msg; if (timeoutTime == -1) { msg = queue.take(); } else { long now = (long)TimeSpan.FromTicks(DateTime.Now.Ticks).TotalMilliseconds; long diff = timeoutTime - now; msg = queue.poll((int)diff); //zakomentowane, bo patrz na queue.poll() // odkomentowane na wszelki wypadek if (msg == null) throw new TimeoutException(); } Message.MessageType type = msg.GetMessageType(); // check if source matches if (node == null || msg.Sender.Equals(node)) { // check if type matches foreach (Message.MessageType t in types) { if (type.Equals(t)) return msg; } } Logger.getInstance().log( "Unexpected message" + msg.ToString(), LOGGING_NAME, Logger.Level.WARNING); } }
/** * <!-- begin-UML-doc --> Metoda wywolywana, gdy nadejdzie nowa wiadomosc. * <!-- end-UML-doc --> * * @param message * @generated * "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)" */ protected abstract void onNewMessage(Message message);
/** * <!-- begin-UML-doc --> Wstawienie wiadomosci do kolejki wiadomosci. * Wiadomosc zostania odebrana gdy zostanie wywolana metoda * waitForMessage(). <!-- end-UML-doc --> * * @param message * @generated * "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)" */ public void processMessage(Message message) { try { this.messageQueue.putMessage(message); } catch (ThreadInterruptedException e) { Logger.getInstance().log(e.Message, "TPC", Logger.Level.SEVERE); } //this.onNewMessage(message); }
//throws InterruptedException // IMPROVEMENT: should be visitor pattern public void process(Message msg) { lock (this) { if (msg is TPCMessage) { processTpcMessage((TPCMessage)msg); } else if (msg is RestoreMessage) { processRestoreMessage((RestoreMessage)msg); } else if (msg is TransactionMessage) { processTransactionMessage((TransactionMessage)msg); } else if (msg is HelloMessage) { processHelloMessage((HelloMessage)msg); } } }
//throws InterruptedException public void putMessage(Message msg) { queue.put(msg); }
//throws InterruptedException, TimeoutException public Message accept(Message.MessageType type, IPEndPoint node) { Message.MessageType[] types = { type }; return accept(types, node); }
/** * /* (non-Javadoc) * * @see TPCParticipant#onNewMessage(TPCMessage message) * * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)" */ protected override void onNewMessage(Message message) { Logger.getInstance().log("NewMessage: " + message, "Coordinator", Logger.Level.INFO); if(message is YesForCommitMessage) { state.onYesForCommit(message.getSender()); } else if(message is NoForCommitMessage) { state.onNoForCommit(message.getSender()); } else if(message is HaveCommittedMessage) { state.onHaveCommitted((HaveCommittedMessage)message); } else if(message is AckPreCommitMessage) { state.onAckPreCommit(message.getSender()); } else if(message is TransactionMessage) { state.onTransaction((TransactionMessage)message); } else if(message is RBD.TPC.Msg.TimeoutMessage) { state.onTimeout(); } else if (message is RBD.TPC.Msg.ErrorMessage) { state.onErrorMessage((RBD.TPC.Msg.ErrorMessage)message); } }
public void sendToNode(Message message, IPEndPoint to) { lock (this) { // begin-user-code byte[] data; if (to == null) { // write to self try { queue.put(message); } catch (ThreadInterruptedException) { Logger.getInstance().log("InterruptedException Cannot send to self", LOGGING_NAME, Logger.Level.SEVERE); } return; } // serialize data = message.Serialize(); NodeInfo node = null; if (nodes.ContainsKey(to)) { node = nodes[to]; } if (node == null) { Logger.getInstance().log("Request to send to unexisting node: " + to.ToString(), LOGGING_NAME, Logger.Level.WARNING); } else { if (!writeToNode(to, node.getSocket(), data)) { nodes.Remove(to); } } // end-user-code } }
public void sendToAllServerNodes(Message message) { lock (this) { // begin-user-code byte[] data; // serialize data = message.Serialize(); // search for server nodes IDictionaryEnumerator it = nodes.GetEnumerator(); //Iterator<Map.Entry<InetSocketAddress, NodeInfo>> it = nodes.entrySet().iterator(); // w javie while (it.MoveNext()) { NodeInfo node = (NodeInfo)it.Value; if (node.getIsServer()) { if (!writeToNode((IPEndPoint)it.Key, node.getSocket(), data)) { // TODO nie czaję tego kawałka -- usuwamy nodes.Remove((IPEndPoint)it.Key); //it.remove(); // w javie } } } // write to self try { queue.put(message); } catch (ThreadInterruptedException) { Logger.getInstance().log("InterruptedException Cannot send to self", LOGGING_NAME, Logger.Level.SEVERE); } } // end-user-code }
public void putMessage(Message message) //throws InterruptedException { messages.put(message); }