89 lines
2.4 KiB
Plaintext
89 lines
2.4 KiB
Plaintext
///////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// 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<ServiceContract.Exp:Start> clientRef;
|
|
|
|
public Journalet(JournalProducer! producer,
|
|
[Claims]ServiceContract.Exp:Start! ep)
|
|
{
|
|
this.producer = producer;
|
|
this.clientRef = new TRef<ServiceContract.Exp:Start>(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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// This thread interposes between the client and the server.
|
|
/// </summary>
|
|
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();
|
|
}
|
|
}
|
|
}
|