/// <summary> /// Gesture that deploys a (non-upgradeable) service. The result is a service that implements the API defined /// in <typeparamref name="T"/>. /// </summary> /// <typeparam name="T">The interface that defines the API of the deployed service.</typeparam> /// <param name="serviceName"></param> /// <param name="instance">The instance to deploy. It must implement <typeparamref name="T"/>.</param> /// <param name="receivePort">The port number on which it listens for messages from Ambrosia.</param> /// <param name="sendPort">The port number which the service uses to send messages to Ambrosia.</param> /// <returns></returns> public static IDisposable Deploy <T>(string serviceName, Immortal instance, int receivePort, int sendPort) { var typeOfT = typeof(T); if (!typeOfT.IsInterface) { throw new ArgumentException($"The type '{typeOfT.Name}' must be an interface."); } var immortalType = instance.GetType(); if (!typeof(IEmpty).IsAssignableFrom(typeOfT) && !immortalType.GetInterfaces().Any(i => i.Equals(typeOfT) || i.IsSubclassOf(typeOfT))) { throw new ArgumentException($"The instance to be deployed is of type '{immortalType.Name}' does not implement the type {typeOfT.Name}."); } // Generate server Ambrosia instance and cache it. Use type parameter T to tell the generation what // interface to generate a proxy for. Immortal.Dispatcher serverContainer; var serializationClass = typeOfT.Assembly.GetTypes().FirstOrDefault(p => p.IsClass && !p.IsAbstract && typeof(ImmortalSerializerBase).IsAssignableFrom(p)); var immortalSerializer = serializationClass == null ? new Immortal.SimpleImmortalSerializer() : (ImmortalSerializerBase)Activator.CreateInstance(serializationClass); if (typeof(IEmpty).IsAssignableFrom(typeOfT)) { serverContainer = new EmptyDispatcher(instance, immortalSerializer, serviceName, receivePort, sendPort); } else { var containerClass = typeOfT.Assembly.GetType(typeOfT.FullName + "_Dispatcher_Implementation"); var container = Activator.CreateInstance(containerClass, instance, immortalSerializer, serviceName, receivePort, sendPort, true); serverContainer = (Immortal.Dispatcher)container; } serverContainer.Start(); return(serverContainer); }
/// <summary> /// Gesture that deploys a (non-upgradeable) service WITH its IC running in the same process, for TTD. The result is a service that implements the API defined /// in <typeparamref name="T"/>. /// </summary> /// <typeparam name="T">The interface that defines the API of the deployed service.</typeparam> /// <param name="serviceName"></param> /// <param name="instance">The instance to deploy. It must implement <typeparamref name="T"/>.</param> /// <param name="serviceLogPath">The path used to get to the logs.</param> /// <param name="checkpointToLoad">The number of the checkpoint to start TTD from</param> /// <param name="currentVersion">The version number used to start TTD from</param> /// <returns></returns> public static IDisposable Deploy <T>(string serviceName, Immortal instance, string serviceLogPath, long checkpointToLoad = 1, int currentVersion = 0) { _iCThread = new Thread(() => { var myRuntime = new AmbrosiaRuntime(); myRuntime.InitializeRepro(serviceName, serviceLogPath, checkpointToLoad, currentVersion, false); }) { IsBackground = true }; _iCThread.Start(); // Wait for the IC to finish setting up the named pipes before continuing (waiting avoids a potential deadlock) while (!AmbrosiaRuntime._listening) { ; } return(Deploy <T>(serviceName, instance, 0, 0)); }
JobContinueAsync(System.Int32 p_0, System.Int64 p_1, JobAPI.BoxedDateTime p_2) { SerializableTaskCompletionSource rpcTask; // Make call, wait for reply // Compute size of serialized arguments var totalArgSize = 0; int arg0Size = 0; byte[] arg0Bytes = null; // Argument 0 arg0Bytes = Ambrosia.BinarySerializer.Serialize <System.Int32>(p_0); arg0Size = IntSize(arg0Bytes.Length) + arg0Bytes.Length; totalArgSize += arg0Size; int arg1Size = 0; byte[] arg1Bytes = null; // Argument 1 arg1Bytes = Ambrosia.BinarySerializer.Serialize <System.Int64>(p_1); arg1Size = IntSize(arg1Bytes.Length) + arg1Bytes.Length; totalArgSize += arg1Size; int arg2Size = 0; byte[] arg2Bytes = null; // Argument 2 arg2Bytes = Ambrosia.BinarySerializer.Serialize <JobAPI.BoxedDateTime>(p_2); arg2Size = IntSize(arg2Bytes.Length) + arg2Bytes.Length; totalArgSize += arg2Size; var wp = this.StartRPC <object>(methodIdentifier: 1 /* method identifier for JobContinue */, lengthOfSerializedArguments: totalArgSize, taskToWaitFor: out rpcTask); var asyncContext = new AsyncContext { SequenceNumber = Immortal.CurrentSequenceNumber }; // Serialize arguments // Serialize arg0 wp.curLength += wp.PageBytes.WriteInt(wp.curLength, arg0Bytes.Length); Buffer.BlockCopy(arg0Bytes, 0, wp.PageBytes, wp.curLength, arg0Bytes.Length); wp.curLength += arg0Bytes.Length; // Serialize arg1 wp.curLength += wp.PageBytes.WriteInt(wp.curLength, arg1Bytes.Length); Buffer.BlockCopy(arg1Bytes, 0, wp.PageBytes, wp.curLength, arg1Bytes.Length); wp.curLength += arg1Bytes.Length; // Serialize arg2 wp.curLength += wp.PageBytes.WriteInt(wp.curLength, arg2Bytes.Length); Buffer.BlockCopy(arg2Bytes, 0, wp.PageBytes, wp.curLength, arg2Bytes.Length); wp.curLength += arg2Bytes.Length; int taskId; lock (Immortal.DispatchTaskIdQueueLock) { while (!Immortal.DispatchTaskIdQueue.Data.TryDequeue(out taskId)) { } } ReleaseBufferAndSend(); Immortal.StartDispatchLoop(); var taskToWaitFor = Immortal.CallCache.Data[asyncContext.SequenceNumber].GetAwaitableTaskWithAdditionalInfoAsync(); var currentResult = await taskToWaitFor; while (currentResult.AdditionalInfoType != ResultAdditionalInfoTypes.SetResult) { switch (currentResult.AdditionalInfoType) { case ResultAdditionalInfoTypes.SaveContext: await Immortal.SaveTaskContextAsync(); taskToWaitFor = Immortal.CallCache.Data[asyncContext.SequenceNumber].GetAwaitableTaskWithAdditionalInfoAsync(); break; case ResultAdditionalInfoTypes.TakeCheckpoint: var sequenceNumber = await Immortal.TakeTaskCheckpointAsync(); Immortal.StartDispatchLoop(); taskToWaitFor = Immortal.GetTaskToWaitForWithAdditionalInfoAsync(sequenceNumber); break; } currentResult = await taskToWaitFor; } lock (Immortal.DispatchTaskIdQueueLock) { Immortal.DispatchTaskIdQueue.Data.Enqueue(taskId); } return; }
public EmptyDispatcher(Immortal c, ImmortalSerializerBase myImmortalSerializer, string serviceName, int receivePort, int sendPort) : base(c, myImmortalSerializer, serviceName, receivePort, sendPort, true) { }
public EmptyDispatcher(Immortal c, ImmortalSerializerBase myImmortalSerializer, string serviceName, Type newInterface, Type newImmortal, int receivePort, int sendPort) : base(c, myImmortalSerializer, serviceName, newInterface, newImmortal, receivePort, sendPort) { }
// Start is called before the first frame update void Start() { manager = GameObject.FindGameObjectWithTag("Manager"); managerScript = manager.GetComponent <Immortal>(); }
public IServer_Dispatcher_Implementation(Immortal z, ImmortalSerializerBase myImmortalSerializer, string localAmbrosiaRuntime, Type newInterface, Type newImmortalType, int receivePort, int sendPort) : base(z, myImmortalSerializer, localAmbrosiaRuntime, newInterface, newImmortalType, receivePort, sendPort) { this.instance = (IServer)z; }
public IServer_Dispatcher_Implementation(Immortal z, ImmortalSerializerBase myImmortalSerializer, string serviceName, int receivePort, int sendPort, bool setupConnections) : base(z, myImmortalSerializer, serviceName, receivePort, sendPort, setupConnections) { this.instance = (IServer)z; }
GetItemsAsync(System.Boolean p_0) { SerializableTaskCompletionSource rpcTask; // Make call, wait for reply // Compute size of serialized arguments var totalArgSize = 0; var p_1 = default(CommInterfaceClasses.Item[]); int arg0Size = 0; byte[] arg0Bytes = null; // Argument 0 arg0Bytes = Ambrosia.BinarySerializer.Serialize <System.Boolean>(p_0); arg0Size = IntSize(arg0Bytes.Length) + arg0Bytes.Length; totalArgSize += arg0Size; var wp = this.StartRPC <CommInterfaceClasses.Item[]>(methodIdentifier: 8 /* method identifier for GetItems */, lengthOfSerializedArguments: totalArgSize, taskToWaitFor: out rpcTask); var asyncContext = new AsyncContext { SequenceNumber = Immortal.CurrentSequenceNumber }; // Serialize arguments // Serialize arg0 wp.curLength += wp.PageBytes.WriteInt(wp.curLength, arg0Bytes.Length); Buffer.BlockCopy(arg0Bytes, 0, wp.PageBytes, wp.curLength, arg0Bytes.Length); wp.curLength += arg0Bytes.Length; int taskId; lock (Immortal.DispatchTaskIdQueueLock) { while (!Immortal.DispatchTaskIdQueue.Data.TryDequeue(out taskId)) { } } ReleaseBufferAndSend(); Immortal.StartDispatchLoop(); var taskToWaitFor = Immortal.CallCache.Data[asyncContext.SequenceNumber].GetAwaitableTaskWithAdditionalInfoAsync(); var currentResult = await taskToWaitFor; while (currentResult.AdditionalInfoType != ResultAdditionalInfoTypes.SetResult) { switch (currentResult.AdditionalInfoType) { case ResultAdditionalInfoTypes.SaveContext: await Immortal.SaveTaskContextAsync(); taskToWaitFor = Immortal.CallCache.Data[asyncContext.SequenceNumber].GetAwaitableTaskWithAdditionalInfoAsync(); break; case ResultAdditionalInfoTypes.TakeCheckpoint: var sequenceNumber = await Immortal.TakeTaskCheckpointAsync(); Immortal.StartDispatchLoop(); taskToWaitFor = Immortal.GetTaskToWaitForWithAdditionalInfoAsync(sequenceNumber); break; } currentResult = await taskToWaitFor; } lock (Immortal.DispatchTaskIdQueueLock) { Immortal.DispatchTaskIdQueue.Data.Enqueue(taskId); } return((CommInterfaceClasses.Item[])currentResult.Result); }
PrintMessageAsync(System.String p_0, System.Double p_1) { SerializableTaskCompletionSource rpcTask; // Make call, wait for reply // Compute size of serialized arguments var totalArgSize = 0; int arg0Size = 0; byte[] arg0Bytes = null; // Argument 0 arg0Bytes = Ambrosia.BinarySerializer.Serialize <System.String>(p_0); arg0Size = IntSize(arg0Bytes.Length) + arg0Bytes.Length; totalArgSize += arg0Size; int arg1Size = 0; byte[] arg1Bytes = null; // Argument 1 arg1Bytes = Ambrosia.BinarySerializer.Serialize <System.Double>(p_1); arg1Size = IntSize(arg1Bytes.Length) + arg1Bytes.Length; totalArgSize += arg1Size; var wp = this.StartRPC <object>(methodIdentifier: 2 /* method identifier for PrintMessage */, lengthOfSerializedArguments: totalArgSize, taskToWaitFor: out rpcTask); var asyncContext = new AsyncContext { SequenceNumber = Immortal.CurrentSequenceNumber }; // Serialize arguments // Serialize arg0 wp.curLength += wp.PageBytes.WriteInt(wp.curLength, arg0Bytes.Length); Buffer.BlockCopy(arg0Bytes, 0, wp.PageBytes, wp.curLength, arg0Bytes.Length); wp.curLength += arg0Bytes.Length; // Serialize arg1 wp.curLength += wp.PageBytes.WriteInt(wp.curLength, arg1Bytes.Length); Buffer.BlockCopy(arg1Bytes, 0, wp.PageBytes, wp.curLength, arg1Bytes.Length); wp.curLength += arg1Bytes.Length; ReleaseBufferAndSend(); var taskToWaitFor = Immortal.CallCache.Data[asyncContext.SequenceNumber].GetAwaitableTaskWithAdditionalInfoAsync(); var currentResult = await taskToWaitFor; var isSaved = await Immortal.TrySaveContextContinuationAsync(currentResult); if (isSaved) { taskToWaitFor = Immortal.CallCache.Data[asyncContext.SequenceNumber].GetAwaitableTaskWithAdditionalInfoAsync(); currentResult = await taskToWaitFor; } await Immortal.TryTakeCheckpointContinuationAsync(currentResult); return; }
private void Start() { managerScript = manager.GetComponent <Immortal>(); }
public ConsoleImmortal(Immortal c, string dataCenterName) : base(c, new Immortal.SimpleImmortalSerializer(), dataCenterName, -1 /*ignored when not setting up connections*/, -1 /*ignored when not setting up connections*/, false) { }
public List <Build> ProtossBuilds(Bot bot) { List <Build> options = new List <Build>(); if (Bot.Debug) { foreach (Strategy strategy in bot.EnemyStrategyAnalyzer.Strategies) { if (strategy.DetectedPreviously) { System.Console.WriteLine("Detected previous strategy: " + strategy.Name()); } } } if (bot.EnemyRace == Race.Terran) { if (Marine.Get().DetectedPreviously && !Reaper.Get().DetectedPreviously && !Marauder.Get().DetectedPreviously && !Cyclone.Get().DetectedPreviously && !Banshee.Get().DetectedPreviously && !SiegeTank.Get().DetectedPreviously && !Medivac.Get().DetectedPreviously && !Viking.Get().DetectedPreviously && !Raven.Get().DetectedPreviously && !Battlecruiser.Get().DetectedPreviously && !WidowMine.Get().DetectedPreviously && !Hellion.Get().DetectedPreviously && !Thor.Get().DetectedPreviously && !Liberator.Get().DetectedPreviously) { // ValinMarineBot options.Add(new NinjaTurtles()); return(options); } if (BattlecruiserRush.Get().DetectedPreviously && Thor.Get().DetectedPreviously && WidowMine.Get().DetectedPreviously) { // BenBotBC options.Add(new OneBaseStalkerImmortal()); return(options); } if (Battlecruiser.Get().DetectedPreviously && !BattlecruiserRush.Get().DetectedPreviously && !Marauder.Get().DetectedPreviously && !Banshee.Get().DetectedPreviously && !Reaper.Get().DetectedPreviously && !Cyclone.Get().DetectedPreviously && !Medivac.Get().DetectedPreviously && !Raven.Get().DetectedPreviously) { options.Add(new MassVoidray() { SkipDefenses = true }); return(options); } /* * if (ProxyDetected.Get().DetectedPreviously * && !Marauder.Get().DetectedPreviously * && Banshee.Get().DetectedPreviously) * { * options.Add(new AntiMicro()); * return options; * } */ if (ProxyDetected.Get().DetectedPreviously && Marauder.Get().DetectedPreviously && Banshee.Get().DetectedPreviously) { // MicroMachine options.Add(new AntiMicro() { HuntProxies = true, CounterProxyMarauder = false }); //options.Add(new NinjaTurtles() { Expand = true }); //options.Add(new OneBaseTempest() { DefendingStalker = true }); return(options); } if (ProxyDetected.Get().DetectedPreviously && !Banshee.Get().DetectedPreviously) { // Strelok //options.Add(new PvTStalkerImmortal() { BuildReaperWall = true, ProxyPylon = false, DelayObserver = true, SendScout = true, MassTanksDetected = MassTank.Get().DetectedPreviously }); options.Add(new OneBaseStalkerImmortal() { UseSentry = true }); options.Add(new OneBaseTempest()); return(options); } if (Marine.Get().DetectedPreviously && Medivac.Get().DetectedPreviously && Viking.Get().DetectedPreviously && Reaper.Get().DetectedPreviously && Raven.Get().DetectedPreviously && !Cyclone.Get().DetectedPreviously && !Marauder.Get().DetectedPreviously && !Banshee.Get().DetectedPreviously) { options.Add(new OneBaseStalkerImmortal()); //options.Add(new PvTStalkerImmortal() { BuildReaperWall = false, ProxyPylon = false, DelayObserver = true, SendScout = false, MassTanksDetected = true }); return(options); } if (Marine.Get().DetectedPreviously && Medivac.Get().DetectedPreviously && Viking.Get().DetectedPreviously && Reaper.Get().DetectedPreviously && !Raven.Get().DetectedPreviously && Marauder.Get().DetectedPreviously && Liberator.Get().DetectedPreviously && !Banshee.Get().DetectedPreviously) { // Jensiiibot //options.Add(new PvTStalkerTempest()); //options.Add(new Builds.Protoss.WorkerRush() { CounterJensiii = true, BuildStalkers = true }); //options.Add(new PvTStalkerImmortal() { BuildReaperWall = true, ProxyPylon = false, DelayObserver = true, MassTanksDetected = MassTank.Get().DetectedPreviously, UseColosus = false }); options.Add(new PvTZealotImmortal()); return(options); } if (Marine.Get().DetectedPreviously && Medivac.Get().DetectedPreviously && Viking.Get().DetectedPreviously && Reaper.Get().DetectedPreviously && Cyclone.Get().DetectedPreviously && !Marauder.Get().DetectedPreviously && !Liberator.Get().DetectedPreviously && !Banshee.Get().DetectedPreviously) { // Rusty options.Add(new OneBaseStalkerImmortal()); return(options); } if (Marine.Get().DetectedPreviously && Medivac.Get().DetectedPreviously && Viking.Get().DetectedPreviously && Reaper.Get().DetectedPreviously && !Raven.Get().DetectedPreviously && Cyclone.Get().DetectedPreviously && Marauder.Get().DetectedPreviously && !Liberator.Get().DetectedPreviously && !Banshee.Get().DetectedPreviously && Thor.Get().DetectedPreviously && SiegeTank.Get().DetectedPreviously && MassTank.Get().DetectedPreviously && Hellbat.Get().DetectedPreviously) { // MechSweep options.Add(new OneBaseTempest() { RequiredSize = 3 }); return(options); } options.Add(new PvTStalkerImmortal() { BuildReaperWall = true, ProxyPylon = false, DelayObserver = true, MassTanksDetected = MassTank.Get().DetectedPreviously, UseColosus = false }); } else if (bot.EnemyRace == Race.Zerg) { if (Bot.Main.OpponentID == "eed44128-f488-4e31-b457-8e55f8a95628") { options.Add(new PvZHjax() { CounterRoaches = false, DefendNydus = false }); return(options); } options.Add(new PvZHjax()); return(options); /* * if (Lurker.Get().DetectedPreviously) * { * //Kagamine * //options.Add(new PvZAdeptIntoVoidray()); * //options.Add(new WorkerRush()); * options.Add(new PvZHjax()); * return options; * } * if (Mutalisk.Get().DetectedPreviously * && !Lurker.Get().DetectedPreviously) * { * options.Add(new OneBaseStalkerImmortal() { StartZealots = true }); * return options; * } * if (Hydralisk.Get().DetectedPreviously && StrategyAnalysis.ZerglingRush.Get().DetectedPreviously) * { * options.Add(new ZealotRush()); * return options; * } * if (RoachRush.Get().DetectedPreviously || StrategyAnalysis.ZerglingRush.Get().DetectedPreviously) * { * options.Add(new PvZRushDefense()); * options.Add(new NinjaTurtles()); * return options; * } * if (Roach.Get().DetectedPreviously * && Zergling.Get().DetectedPreviously * && !Hydralisk.Get().DetectedPreviously) * { * options.Add(new PvZRushDefense()); * options.Add(new NinjaTurtles()); * return options; * } * if (Queen.Get().DetectedPreviously * && Zergling.Get().DetectedPreviously * && !Hydralisk.Get().DetectedPreviously * && !Roach.Get().DetectedPreviously) * { * options.Add(new NinjaTurtles()); * return options; * } * if (bot.PreviousEnemyStrategies.MassHydra * && MassRoach.Get().DetectedPreviously * && !Lurker.Get().DetectedPreviously) * { * options.Add(new OneBaseTempest()); * return options; * } * if (!Zergling.Get().DetectedPreviously * && !Roach.Get().DetectedPreviously * && !Hydralisk.Get().DetectedPreviously * && !Queen.Get().DetectedPreviously * && !Mutalisk.Get().DetectedPreviously) * { * options.Add(new OneBaseTempest()); * return options; * } * if (!Zergling.Get().DetectedPreviously * && Roach.Get().DetectedPreviously * && !Hydralisk.Get().DetectedPreviously * && Queen.Get().DetectedPreviously * && !Mutalisk.Get().DetectedPreviously) * { * options.Add(new OneBaseTempest()); * return options; * } * options.Add(new OneBaseStalkerImmortal() { StartZealots = true }); */ } else if (bot.EnemyRace == Race.Protoss) { if (Zealot.Get().DetectedPreviously && VoidRay.Get().DetectedPreviously && !Carrier.Get().DetectedPreviously && !Tempest.Get().DetectedPreviously && !Stalker.Get().DetectedPreviously && !Adept.Get().DetectedPreviously && !Immortal.Get().DetectedPreviously && !StrategyAnalysis.CannonRush.Get().DetectedPreviously) { // MavBot3 options.Add(new ZealotRush()); return(options); } if (SkippedNatural.Get().DetectedPreviously && !AdeptHarass.Get().DetectedPreviously && VoidRay.Get().DetectedPreviously && Immortal.Get().DetectedPreviously) { // AdditionalPylons options.Add(new DoubleRoboProxy()); return(options); } if (Oracle.Get().DetectedPreviously && ThreeGate.Get().DetectedPreviously && Zealot.Get().DetectedPreviously && !Stalker.Get().DetectedPreviously && !VoidRay.Get().DetectedPreviously && !Immortal.Get().DetectedPreviously) { // LuckyBot options.Add(new OneBaseTempest()); return(options); } if (Carrier.Get().DetectedPreviously && Collosus.Get().DetectedPreviously && SkyToss.Get().DetectedPreviously && Tempest.Get().DetectedPreviously && !Archon.Get().DetectedPreviously && !HighTemplar.Get().DetectedPreviously) { // TheGoldenArmada options.Add(new OneBaseTempest()); return(options); } options.Add(new OneBaseStalkerImmortal() { DoubleRobo = true, EarlySentry = true, AggressiveMicro = true }); return(options); /* * if (AdeptHarass.Get().DetectedPreviously * && SkyToss.Get().DetectedPreviously * && Carrier.Get().DetectedPreviously * && HighTemplar.Get().DetectedPreviously * && VoidRay.Get().DetectedPreviously * && !StrategyAnalysis.CannonRush.Get().DetectedPreviously) * { * options.Add(new ZealotRush()); * options.Add(new OneBaseStalkerImmortal()); * return options; * } * if (AdeptHarass.Get().DetectedPreviously) * { * // SharpenedEdge * options.Add(new OneBaseTempest()); * options.Add(new Dishwasher()); * return options; * } * if (StrategyAnalysis.CannonRush.Get().DetectedPreviously * && Tempest.Get().DetectedPreviously) * { * // ThreeWayLover * //options.Add(new MassVoidray() { SkipDefenses = true }); * options.Add(new OneBaseTempest()); * return options; * } * if (Sentry.Get().DetectedPreviously * && Archon.Get().DetectedPreviously * && !Stalker.Get().DetectedPreviously * && !Zealot.Get().DetectedPreviously) * { * options.Add(new TempestProxy()); * return options; * } * if (Zealot.Get().DetectedPreviously * && StrategyAnalysis.CannonRush.Get().DetectedPreviously * && Oracle.Get().DetectedPreviously * && Phoenix.Get().DetectedPreviously * && Stalker.Get().DetectedPreviously * && !Immortal.Get().DetectedPreviously) * { * //Gumby * options.Add(new NinjaTurtles()); * return options; * } * if (Oracle.Get().DetectedPreviously) * { * options.Add(new OneBaseTempest()); * return options; * } * if (!Stalker.Get().DetectedPreviously * && !Zealot.Get().DetectedPreviously * && !Sentry.Get().DetectedPreviously) * { * options.Add(new ZealotRush()); * return options; * } * if (Zealot.Get().DetectedPreviously * && !Stalker.Get().DetectedPreviously) * { * options.Add(new NinjaTurtles()); * return options; * } * * options.Add(new NinjaTurtles()); * options.Add(new PvPMothershipSiege()); */ } return(options); }