/////////////////////////////////////////////////////////////////////////////// // // Microsoft Research Singularity // // Copyright (c) Microsoft Corporation. All rights reserved. // // File: Libraries\Resiliency\Journalet.sg // // Note: Logging Worker Template // using System; using System.Threading; using Microsoft.SingSharp; using Microsoft.Singularity; using Microsoft.Singularity.Channels; using Microsoft.Singularity.Directory; using Microsoft.Singularity.ServiceManager; using Microsoft.Singularity.Services; namespace Microsoft.Singularity.Resiliency { public abstract class Journalet { protected JournalProducer! producer; protected Thread serviceThread; protected TRef clientRef; public Journalet(JournalProducer! producer, [Claims]ServiceContract.Exp:Start! ep) { this.producer = producer; this.clientRef = new TRef(ep); } public abstract void CreateServerEndpoint(out ServiceContract.Exp:Start! ep); protected virtual bool Initialize() { return true; } protected virtual bool HandleMessages() { return true; } protected virtual bool Recover() { return true; } /// /// This thread interposes between the client and the server. /// protected virtual void ProxyThread() { if (!Initialize()) { goto exit; } for (;;) { if (!HandleMessages()) { goto exit; } try { if (!Recover()) { goto exit; } } catch (Exception e) { DebugStub.WriteLine("ProxyThread: Exception caught."); DebugStub.WriteLine(e.ToString()); } } exit: producer.DeregisterJournalet(this); return; } public void Start() { ThreadTerminationContract.Imp! sender; ThreadTerminationContract.Exp! receiver; serviceThread = new Thread(new ThreadStart(ProxyThread)); serviceThread.Start(); } } }