public static bool Init() { _channel = new TcpChannel(); ChannelServices.RegisterChannel(_channel, false); _master = (MasterInterface)Activator.GetObject(typeof(MasterInterface), "tcp://localhost:8087/Server"); _isInTransaction = false; _references = new Dictionary <int, PADInt>(); _serverList = new List <string>(); return(true); }
public TransactionalServer(int id, MasterInterface master, string url) { _id = id; _padints = new Dictionary <int, PADInt>(); _transactions = new Dictionary <int, List <int> >(); _pendingRequests = new Dictionary <MethodInfo, List <Object> >(); _alive = new Timer(TIMEOUT); _alive.Elapsed += IsAlive; _alive.Enabled = true; _master = master; _url = url; _prepared = false; _status = true; }
static void Main(string[] args) { RemotingConfiguration.Configure(@"../../App.config", true); KeyValuePair <int, int> idAndPort; System.Console.WriteLine("Bootstrapping..."); TcpChannel channel = new TcpChannel(); ChannelServices.RegisterChannel(channel, false); System.Console.WriteLine("Registered Channel @random"); string address = System.IO.File.ReadAllText(@"../../../mServerLocation.dat"); MasterInterface mServer = (MasterInterface)Activator.GetObject(typeof(MasterInterface), address); idAndPort = mServer.RegisterTransactionalServer(getIP()); System.Console.WriteLine("Registered at Master"); ChannelServices.UnregisterChannel(channel); System.Console.WriteLine("Unbinding old port"); BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider(); provider.TypeFilterLevel = TypeFilterLevel.Full; IDictionary props = new Hashtable(); props["port"] = idAndPort.Value; channel = new TcpChannel(props, null, provider); ChannelServices.RegisterChannel(channel, false); System.Console.WriteLine("Registered Channel @" + idAndPort.Value); TransactionalServer ts = new TransactionalServer(idAndPort.Key, mServer, "tcp://" + getIP() + ":" + idAndPort.Value + "/Server"); RemotingServices.Marshal(ts, "Server", typeof(TransactionalServer)); System.Console.WriteLine("SERVER ON"); System.Console.WriteLine("Server: " + idAndPort.Key + " Port: " + idAndPort.Value + " IP: " + getIP()); System.Console.ReadLine(); }
public void CreateReservation(String description, List<UserView> userList, List<ReservationSlot> slotList, String creator, MasterInterface master) { if (!User.IsRegistered) { User.Register(); } Console.WriteLine("[Calling] CreateReservation"); Console.WriteLine("Printing slot list.."); foreach (ReservationSlot s in slotList) { Console.WriteLine(s.ToString()); } int ticket = master.RequestTicketNumber(); Reservation reservation = new Reservation(description, userList, slotList, creator, ticket); //reservation has no participants. Medical dentist consult example if (userList.Count == 0) { Console.WriteLine("No participants"); SinglePersonReservation(slotList, reservation); return; } User.CreatedReservations.Add(reservation); ChangeCalendarSlotStatus(slotList, true); ReservationMessage reservationMessage = new ReservationMessage(); reservationMessage.senderName = User.Name; reservationMessage.reservation = reservation; reservationMessage.messageCounter = 1; //send reservation DisseminateInformation(reservationMessage, MessageTypeToDisseminate.SEND_RESERVATION,false); List<UserView> usersThatNotAnswered = UsersThatNotAnsweredSendReservationCall(reservationMessage.reservation, false); if (usersThatNotAnswered.Count == 0) { Console.WriteLine("All users have answered"); } else { List<UserView> newList = RemoveUsersThatNotAnsweredFromTheUserList(reservationMessage.reservation.getUserList(), usersThatNotAnswered); localThreadList.Clear(); threadResponses.Clear(); threadResponses2.Clear(); disseminationThreadList.Clear(); PrepareRetrySendReservation(usersThatNotAnswered, reservationMessage); usersThatNotAnswered.Clear(); usersThatNotAnswered = UsersThatNotAnsweredSendReservationCall(reservationMessage.reservation, true); Console.WriteLine("Not answered retry!"); foreach (UserView u in usersThatNotAnswered) { Console.WriteLine("User " + u.getName() + " did not answered. Dead? Maybe..."); } newList = RemoveUsersThatNotAnsweredFromTheUserList(reservationMessage.reservation.getUserList(), usersThatNotAnswered); if (newList.Count == 0) { DisseminateInformation(reservationMessage, MessageTypeToDisseminate.ABORT_RESERVATION, false); localThreadList.Clear(); disseminationThreadList.Clear(); threadResponses.Clear(); threadResponses2.Clear(); return; } reservationMessage.reservation.SetUserList(newList); } localThreadList.Clear(); //changes the reservation slot status based on the answers received //if the reservation if null them all slots are aborted -> Abort the reservation Reservation temporaryReservation = null; temporaryReservation = ChangeReservationSlotStatus(reservationMessage.reservation); if (temporaryReservation == null) { DisseminateInformation(reservationMessage, MessageTypeToDisseminate.ABORT_RESERVATION, false); localThreadList.Clear(); threadResponses.Clear(); return; } reservationMessage.reservation = temporaryReservation; reservationMessage.reservation = DeleteAbortedSlotsFromReservation(reservationMessage.reservation); PrintReservation(reservationMessage.reservation); //debug threadResponses.Clear(); //sends information to the users about the state of the reservation slots DisseminateInformation(reservationMessage, MessageTypeToDisseminate.UPDATE_USERS_RESERVATION_INFO, false); //remove the aborted slots from the slotList and start proposing possible slots for the event localThreadList.Clear(); threadResponses.Clear(); //there are no avaible slots if (reservationMessage.reservation.getSlotList().Count == 0) { Console.WriteLine("No avaiable slots. Abort Reservation"); DisseminateInformation(reservationMessage, MessageTypeToDisseminate.ABORT_RESERVATION, false); localThreadList.Clear(); threadResponses.Clear(); return; } bool wasAccepted = false; int slotListSize = reservationMessage.reservation.getSlotList().Count; ReservationMessage proposedSlotMessage = new ReservationMessage(); ReservationSlot commitSlot = null; for (int i = 0; i <= slotListSize; i++) { proposedSlotMessage = CreateMessageWithProposedSlot(reservationMessage.reservation, reservationMessage.reservation.getSlotList()[i]); DisseminateInformation(proposedSlotMessage, MessageTypeToDisseminate.PROPOSE_SLOT, false); //check if the proposed slot was accepted by all participants wasAccepted = WasProposedSlotAccepted(proposedSlotMessage.proposedSlot); if (wasAccepted) { { commitSlot = proposedSlotMessage.proposedSlot; break; } } localThreadList.Clear(); threadResponses.Clear(); } Console.WriteLine("Was accepted? " + wasAccepted); if (!wasAccepted) { Console.WriteLine("No slot was accepted! Abort Reservation"); DisseminateInformation(reservationMessage, MessageTypeToDisseminate.ABORT_RESERVATION, false); localThreadList.Clear(); threadResponses.Clear(); return; } Console.WriteLine("AcceptedSlot\n" + proposedSlotMessage.proposedSlot.ToString()); localThreadList.Clear(); threadResponses.Clear(); Console.WriteLine("Starting 2PC"); DisseminateInformation(reservationMessage, MessageTypeToDisseminate.TWO_PHASE_COMMIT, false); usersThatNotAnswered.Clear(); usersThatNotAnswered = UsersThatNotAnsweredTwoPhaseCommit(reservationMessage.reservation,false); if (usersThatNotAnswered.Count == 0) { Console.WriteLine("All users have answered"); } else { List<UserView> newList = RemoveUsersThatNotAnsweredFromTheUserList(reservationMessage.reservation.getUserList(), usersThatNotAnswered); PrepareRetryTwoPhaseCommit(usersThatNotAnswered, reservationMessage); usersThatNotAnswered.Clear(); usersThatNotAnswered = UsersThatNotAnsweredTwoPhaseCommit(reservationMessage.reservation, true); foreach (UserView u in usersThatNotAnswered) { Console.WriteLine("User " + u.getName() + " did not answered. Dead? Maybe..."); } newList = RemoveUsersThatNotAnsweredFromTheUserList(reservationMessage.reservation.getUserList(), usersThatNotAnswered); if (newList.Count == 0) { DisseminateInformation(reservationMessage, MessageTypeToDisseminate.ABORT_RESERVATION, false); localThreadList.Clear(); disseminationThreadList.Clear(); threadResponses.Clear(); threadResponses2.Clear(); return; } reservationMessage.reservation.SetUserList(newList); } Console.WriteLine("Send Commit Reservation!"); ReservationMessage commitMessage = new ReservationMessage(); commitMessage.slotToCommit = commitSlot; commitMessage.reservation = reservationMessage.reservation; commitMessage.senderName = User.Name; commitMessage.messageCounter = 1; DisseminateInformation(commitMessage, MessageTypeToDisseminate.COMMIT_RESERVATION,false) ; CommitReservation(commitMessage, 2000); localThreadList.Clear(); threadResponses.Clear(); }
public TransactionalServer(int id, MasterInterface master, string url) { _id = id; _padints = new Dictionary<int, PADInt>(); _transactions = new Dictionary<int, List<int>>(); _pendingRequests = new Dictionary<MethodInfo, List<Object>>(); _alive = new Timer(TIMEOUT); _alive.Elapsed += IsAlive; _alive.Enabled = true; _master = master; _url = url; _prepared = false; _status = true; }
public static bool Init() { _channel = new TcpChannel(); ChannelServices.RegisterChannel(_channel, false); _master = (MasterInterface)Activator.GetObject(typeof(MasterInterface), "tcp://localhost:8087/Server"); _isInTransaction = false; _references = new Dictionary<int, PADInt>(); _serverList = new List<string>(); return true; }