public static PadInt AccessPadInt(int uid) { try { IPadInt padIntObj; PadIntInfo obj = masterServer.AccessPadInt(uid); if (obj == null) { return(null); } if (!obj.hasPadInt()) // Catch remoting exception { IDataServer dataServer = (IDataServer)Activator.GetObject(typeof(IDataServer), obj.ServerUrl); padIntObj = dataServer.load(uid); } else { padIntObj = obj.PadInt; } PadInt localPadInt = new PadInt(uid, padIntObj); return(localPadInt); } catch (TxException re) { //Console.WriteLine("[AccessPadInt]: Cannot accessPadInt with uid " + uid + "\n" + re); String text = "[AccessPadInt]: Cannot accessPadInt with uid " + uid + "\n" + re; Console.WriteLine(text); //textBox.Invoke(new ClearTextDel(textBox.Clear)); //textBox.Invoke(new UpdateTextDel(textBox.AppendText), new object[] { text }); return(null); } }
// This is the call that the AsyncCallBack delegate will reference. public void ReadAsyncCallBack(IAsyncResult ar) { while (failed_lock == true) { Thread.Sleep(1); } lock (this) { ReadAsyncDelegate del = (ReadAsyncDelegate)((AsyncResult)ar).AsyncDelegate; PadInt padInt = (PadInt)ar.AsyncState; int value = del.EndInvoke(ar); //In case the server never responds -> force kill if (value == Int32.MinValue) { State = TransactionState.ABORTED; failed_lock = false; freeze_lock[(int)padInt.UID] = true; return; } AddValue((int)padInt.UID, value); freeze_lock[(int)padInt.UID] = true; } }
/** * CreatePadInt * @param uid is a global unique identifier for the object in the system * @return PadInt an object representing to the client App what a PadInt is * * CreatePadInt computes the server number based on the uid provided and the number * of servers available in the current transaction. It is guaranteed by the system * that the object with uid is in the server. **/ public static PadInt CreatePadInt(int uid) { if (_transaction.State.Equals(TransactionState.ABORTED)) { // Some server failed Console.WriteLine("Trying to access padint uid=" + uid + " denied because of server failure"); return(null); } int serverNumber = computeDatastore(uid); string serverURL = Servers.AvailableServers[serverNumber]; IDatastoreOps datastore = (IDatastoreOps)Activator.GetObject( typeof(IDatastoreOps), serverURL + "DatastoreOps"); try { bool success = datastore.createPadInt(uid, Transaction.TXID, Client_Url); if (success) { Console.WriteLine("PadiDstm.CreatePadInt TRUE"); PadInt padint = new PadInt(uid, serverURL); Transaction.addAccessedServer(serverURL); return(padint); } else { return(null); } } // If failed catch exception or special number int32.MIN to detect that the server // failed and tell the master to stabilize the system catch (SocketException) { manageFailedServer(serverURL, serverNumber); return(AccessPadInt(uid)); } catch (System.IO.IOException) { manageFailedServer(serverURL, serverNumber); return(AccessPadInt(uid)); } catch (ServerException) { manageFailedServer(serverURL, serverNumber); return(AccessPadInt(uid)); } }
public static PadInt AccessPadInt(int uid) { try { PadIntValue val; val = _server.AccessPadInt(uid); PadInt v = new PadInt(val); _acessedPadInts.Add(v); return v; } catch (TxException e) { throw e; } }
/** * AccessPadInt * @param uid is a global unique identifier for the object in the system * @return PadInt an object representing to the client App what a PadInt is * * AccessPadInt computes the server number based on the uid provided and the number * of servers available in the current transaction. It is guaranteed by the system * that the object with uid is in the server. **/ public static PadInt AccessPadInt(int uid) { if (_transaction.State.Equals(TransactionState.ABORTED)) { // Some server failed Console.WriteLine("Trying to access padint uid=" + uid + " denied because of server failure"); PadInt padint = new PadInt(uid, ""); return(padint); } int serverNumber = computeDatastore(uid); string serverURL = Servers.AvailableServers[serverNumber]; IDatastoreOps datastore = (IDatastoreOps)Activator.GetObject( typeof(IDatastoreOps), serverURL + "DatastoreOps"); try { bool success = datastore.accessPadInt(uid); if (success) { Console.WriteLine("PadiDstm.AccessPadInt TRUE"); PadInt padint = new PadInt(uid, serverURL); Transaction.addAccessedServer(serverURL); return(padint); } else { //Returns null if the object does not exist already. return(null); } } catch (SocketException) { manageFailedServer(serverURL, serverNumber); return(AccessPadInt(uid)); } catch (System.IO.IOException) { manageFailedServer(serverURL, serverNumber); return(AccessPadInt(uid)); } catch (ServerFailedException) { manageFailedServer(serverURL, serverNumber); return(AccessPadInt(uid)); } }
public static PadInt CreatePadInt(int uid) { //Connect to the available server where he will try to create the padint localy and update its location on to the master. try { PadIntValue val; val = _server.CreatePadInt(uid); PadInt v = new PadInt(val); _acessedPadInts.Add(v); return v; } catch (TxException e) { throw e; } }
internal void setListPadInt(PadInt p) { bool ihaveit = false; foreach (PadInt item in this.listPadInt) { if(item.getId() == p.getId()) { this.listPadInt.Remove(item); this.listPadInt.Add(p); ihaveit = true; break; } } if(!ihaveit) this.listPadInt.Add(p); }
public PadInt CreatePadInt(int uid, PadIntMetadata metadata) { checkFreeze(); if (padInts.ContainsKey(uid)) { return null; } PadInt p = new PadInt(uid); foreach (string s in metadata.servers) { p.servers.Add(s); } padInts.Add(uid, p); log.AddNewLogEntry(0, uid, 0); Console.WriteLine("Created PadInt with uid: " + uid); return p; }
public static PadInt AccessPadInt(int uid) { try { Tuple<string, string> urls = _rMasterServer.getUrlOfPadInt(uid); if (urls != null) { RemoteServer server = (RemoteServer)Activator.GetObject(typeof(RemoteServer), urls.Item1); PadInt requestedPadInt = server.accessPadint(uid); if (!padintLocations.ContainsKey(uid)) padintLocations.Add(uid, new Tuple<string, string>(urls.Item1, urls.Item2)); PadInt padintCopy = null; if (padIntList.ContainsKey(uid)) { padintCopy = padIntList[uid]; } else { padintCopy = new PadInt(uid, urls.Item1); } padintCopy.setAllLocalVariables(requestedPadInt.getAllLocalVariables()); padintCopy.setTxId(_actualTxId); if (!padIntList.ContainsKey(uid)) { padIntList.Add(uid, padintCopy); } return padintCopy; } else return null; } catch (TxException txE) { Console.WriteLine(txE.Message); return null; } }
internal int Read(PadInt padInt) { if (State.Equals(TransactionState.ABORTED)) { // Some server failed Console.WriteLine("Trying to access padint uid=" + padInt.UID + " denied because of server failure"); return(-1); } string remotePadIntURL = padInt.URL + "RemotePadInt"; int uid = padInt.UID; freeze_lock.Add(uid, false); IRemotePadInt remote = (IRemotePadInt)Activator.GetObject( typeof(IRemotePadInt), remotePadIntURL); ReadAsyncDelegate RemoteDel = new ReadAsyncDelegate(remote.Read); AsyncCallback RemoteCallback = new AsyncCallback(ReadAsyncCallBack); try { IAsyncResult RemAr = RemoteDel.BeginInvoke(uid, TXID, PadiDstm.Client_Url, RemoteCallback, padInt); } catch (TxException t) { Console.WriteLine("TXEXCEPTION" + t.msg); } timerAlive(padInt.URL); while (!freeze_lock[uid]) { Thread.Sleep(1); } resetTimer(); lock (freeze_lock) { freeze_lock.Remove(uid); } if (State.Equals(TransactionState.ABORTED)) { // Some server failed Console.WriteLine("Trying to access padint uid=" + padInt.UID + " denied because of server failure"); return(-1); } return(values[uid]); }
internal void Write(PadInt padInt, int val) { if (State.Equals(TransactionState.ABORTED)) { Console.WriteLine("Write padint UID= " + padInt.UID + "denied because of server failer"); return; } string remotePadIntURL = padInt.URL + "RemotePadInt"; int uid = padInt.UID; IRemotePadInt remote = (IRemotePadInt)Activator.GetObject( typeof(IRemotePadInt), remotePadIntURL); write_lock = true; WriteAsyncDelegate RemoteDel = new WriteAsyncDelegate(remote.Write); AsyncCallback RemoteCallback = new AsyncCallback(WriteAsyncCallBack); IAsyncResult RemAr = RemoteDel.BeginInvoke(uid, TXID, val, PadiDstm.Client_Url, RemoteCallback, padInt); timerAlive(padInt.URL); while (write_lock) { Thread.Sleep(1); } resetTimer(); //lock (freeze_lock) { freeze_lock.Remove(uid); } if (State.Equals(TransactionState.ABORTED)) { Console.WriteLine("Write padint UID= " + padInt.UID + "denied because of server failer"); return; } // remote.Write(uid, TXID, val, PadiDstm.Client_Url); AddValue(uid, val); addAccessedServer(padInt.URL); }
public static PadInt CreatePadInt(int uid) { try { IPadInt obj = masterServer.CreatePadInt(uid); if (obj == null) { return(null); } else { PadInt localPadInt = new PadInt(uid, obj); return(localPadInt); } } catch (TxException re) { //Console.WriteLine("[CreatePadInt]: Cannot createPadInt with uid " + uid + "\n" + re); String text = "[CreatePadInt]: Cannot createPadInt with uid " + uid + "\n" + re; Console.WriteLine(text); //textBox.Invoke(new ClearTextDel(textBox.Clear)); //textBox.Invoke(new UpdateTextDel(textBox.AppendText), new object[] { text }); return(null); } }
// return - PadInt with the given uid public PadInt accessPadIntOnDataServer(int uid) { if (dataServers.Count == 0) { throw new NoDataServerException("accessPadIntOnDataServer"); } if (!this.locationOfPadInts.ContainsKey(uid)) { throw new InexistentPadIntException(uid); } PadInt padInt = new PadInt(uid, this.getPrimaryDataServerUrl(uid)); Console.WriteLine("Returned PadInt presented into " + this.getPrimaryDataServerUrl(uid)); return padInt; }
public static PadInt AccessPadInt(int uid) { if (!InTransaction) { throw new TxException("Not in a transaction"); } //check if PadInt is locally known PadInt padInt = null; if (padIntsMap.TryGetValue(uid, out padInt)) return padInt; //check if the server for that PadInt is known bool padintServerKnown = KnownPadInts.TryGetValue(uid, out server); if (!padintServerKnown) { string serverURL = master.findPadIntServer(uid); bool serverFound = !serverURL.Equals(Constants.NOT_FOUND); if (serverFound) { server = (iServer)Activator.GetObject(typeof(iServer), serverURL); KnownPadInts.Add(uid, server); padintServerKnown = true; } } if (!padintServerKnown) return null; bool serverKnowsPadInt = false; try { ThreadStart del = () => serverKnowsPadInt = server.hasPadInt(uid, currTransaction); bool succeeded = SharedMethods.tryRemoteCall(del); if (!succeeded) { //FIXME retry to get server iServer s = refreshServerForPadInt(uid); ThreadStart secDel = () => serverKnowsPadInt = s.hasPadInt(uid, currTransaction); bool suc = SharedMethods.tryRemoteCall(secDel); if (!suc) { throw new TxException("Server given by master was failed."); } } //serverKnowsPadInt = server.hasPadInt(uid, currTransaction); } catch (NetworkException netException) { throw new TxException(netException.CustomMessage); } if (!serverKnowsPadInt) { throw new TxException("Inconsistency. Server should know about it's padints."); } PadInt newPadInt = new PadInt(uid); padIntsMap.Add(uid, newPadInt); return newPadInt; }
public static PadInt CreatePadInt(int uid) { if (!InTransaction) { throw new TxException("Not in a transaction"); } PadInt padInt = null; if (padIntsMap.TryGetValue(uid, out padInt) || temporaryPadInts.TryGetValue(uid, out padInt)) { return null; //already exists (cf.enunciado) } string serverURL = master.findPadIntServer(uid); bool serverNotFound = serverURL.Equals(Constants.NOT_FOUND); if (serverNotFound) { try { serverURL = master.getServerLessCharged(currTransaction); server = (iServer)Activator.GetObject(typeof(iServer), serverURL); KnownPadInts.Add(uid, server); ThreadStart myDel = () => server.createPadInt(uid, currTransaction); bool succeeded = SharedMethods.tryRemoteCall(myDel); if (!succeeded) { //FIXME retry to get server iServer s = refreshServerForPadInt(uid); ThreadStart secDel = () => s.createPadInt(uid, currTransaction); bool suc = SharedMethods.tryRemoteCall(secDel); if (!suc) { throw new TxException("Server given by master was failed."); } } //server.createPadInt(uid, currTransaction); padInt = new PadInt(uid); temporaryPadInts.Add(uid, padInt); return padInt; } catch (NetworkException netException) { throw new TxException(netException.CustomMessage); } } return null; //already exists }
public void StorePadInt(int uid, PadInt p) { if (!padInts.Keys.Contains(uid)) { p.servers.Add(myUrl); padInts.Add(uid, p); Console.WriteLine("Re-Stored PadInt with uid {0}.", uid); } else { padInts[uid] = p; } }