Esempio n. 1
0
        //throws InterruptedException
        public void processTpcMessage(TPCMessage msg)
        {
            String transactionId = msg.getTransactionId();

            if (msg is CanCommitMessage)
            {
                // check if cohort already exists
                if (cohorts.ContainsKey(transactionId))
                {
                    Logger.getInstance().log(
                            "Cohort already exists for tid: " + transactionId,
                            LOGGING_NAME,
                            Logger.Level.WARNING);

                    return;
                }

                Logger.getInstance().log(
                        "Creating new cohort with tid " + transactionId + " : " + msg.toString(),
                        LOGGING_NAME,
                        Logger.Level.INFO);

                // create cohort and start his job
                Cohort coh = new CohortImpl();
                cohorts[transactionId] = coh;
                coh.setTransactionId(transactionId);
                coh.setCoordinatorAddress(msg.getSender());
                coh.setDatabaseState(DatabaseStateImpl.getInstance());
                coh.setConnector(DbConnectorImpl.getInstance());
                coh.addEndTransactionListener(this);
                coh.processMessage(msg);

            }
            else if (msg is PreCommitMessage
                    || msg is DoCommitMessage
                    || msg is AbortMessage)
            {
                Logger.getInstance().log(
                        "Dispatching to cohort with tid " + transactionId + " : " + msg.toString(),
                        LOGGING_NAME,
                        Logger.Level.INFO);

                // check if cohort exists
                Cohort cohort = null;
                if (cohorts.ContainsKey(transactionId))
                {
                    cohort = cohorts[transactionId];
                }
                if (cohort == null)
                {
                    Logger.getInstance().log(
                            "No cohort for tid" + transactionId,
                            LOGGING_NAME,
                            Logger.Level.WARNING);
                    return;
                }

                cohort.processMessage(msg);
            }
            else if (msg is YesForCommitMessage
                    || msg is NoForCommitMessage
                    || msg is AckPreCommitMessage
                    || msg is HaveCommittedMessage
                    || msg is RBD.TPC.Msg.ErrorMessage)
            {
                Logger.getInstance().log(
                        "Dispatching to coordinator with tid " + transactionId + " : " + msg.toString(),
                        LOGGING_NAME,
                        Logger.Level.INFO);

                // send to COORDINATOR
                Coordinator coordinator = null;
                if (coordinators.ContainsKey(transactionId))
                {
                    coordinator = coordinators[transactionId];
                }
                if (coordinator == null)
                {
                    //				Logger.getInstance().log(
                    //						"No coordinator for tid" + transactionId,
                    //						LOGGING_NAME,
                    //						Logger.Level.WARNING);
                    return;
                }

                coordinator.processMessage(msg);
            }
        }
Esempio n. 2
0
 /**
  * Wyslij wiadomosc do wszystkich wezlow bioracych udzial w transakcji.
  * @param message
  * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
  */
 public void broadcastMessage(TPCMessage message)
 {
     this.clearAnswers();
     message.TransactionId = this.TransactionId;
     TcpSender.getInstance().sendToAllServerNodes(message);
 }
Esempio n. 3
0
 public abstract void replyToCoordinator(TPCMessage message);
Esempio n. 4
0
 /**
  * <!-- begin-UML-doc -->
  * <p>
  *     Obsluguje odpowiedz wezla na wiadomosc.
  * </p>
  * <p>
  *     Jezeli nie jest to ostatni wezel, to koordynator czeka na nastepna wiadomosc.
  * </p>
  * <p>
  *     Jezeli jest to ostatni wezel, to koordynator wysyla nastepna wiadomosc do wszystkich wezlow uczestniczacych w
  *     transakcji oraz zmienia stan.
  * </p>
  * <!-- end-UML-doc -->
  * @param node <p>
  *    Wezel, ktory odpowiedzial na poprzednia wiadomosc.
  * /p>
  * @param message Nastepna wiadomosc do wyslania do wszystkich wezlow uczestniczacych w transakcji.
  * @param nextState Nastepny stan.
  * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
  */
 public void processAnswer(IPEndPoint node, TPCMessage message, CoordinatorState nextState)
 {
     addAnswer(node);
     if(checkAnswers()) {
     broadcastMessage(message);
     changeState(nextState);
     }
 }
Esempio n. 5
0
 public override void replyToCoordinator(TPCMessage message)
 {
     message.setTransactionId(getTransactionId());
     TcpSender.getInstance().sendToNode(message, getCoordinatorAddress());
 }