public static bool TxCommit() { if (_transaction.State.Equals(TransactionState.ABORTED)) { // Some server failed return(false); } if (Transaction.ACCESSEDSERVERS.Count > 0) { bool success = false; List <string> participants = Transaction.ACCESSEDSERVERS; string coordURL = participants.ElementAt(0); participants.RemoveAt(0); IDatastoreOps datastore = (IDatastoreOps)Activator.GetObject( typeof(IDatastoreOps), coordURL + "DatastoreOps"); Console.WriteLine("PadiDstm.TxCommit: Before commit in Datastore"); success = datastore.commit(Transaction.TXID, participants); Console.WriteLine("PadiDstm.TxCommit: After commit in Datastore"); _transaction = null; return(success); } _transaction = null; return(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)); } }
/** * 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)); } }