102 lines
3.3 KiB
Plaintext
102 lines
3.3 KiB
Plaintext
|
///////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// Microsoft Research Singularity
|
||
|
//
|
||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||
|
//
|
||
|
// File: Services\Tests\CounterProxy\CounterJournalProducer.sg
|
||
|
//
|
||
|
// Note:
|
||
|
//
|
||
|
using System;
|
||
|
using Microsoft.SingSharp;
|
||
|
using Microsoft.SingSharp.Reflection;
|
||
|
using Microsoft.Singularity;
|
||
|
using Microsoft.Singularity.Channels;
|
||
|
using Microsoft.Singularity.Configuration;
|
||
|
using Microsoft.Singularity.Directory;
|
||
|
using Microsoft.Singularity.Resiliency;
|
||
|
using Microsoft.Singularity.Security;
|
||
|
using Microsoft.Singularity.ServiceManager;
|
||
|
using Microsoft.Singularity.Services;
|
||
|
|
||
|
[assembly: Transform(typeof(ServiceResourceTransform))]
|
||
|
[assembly: ApplicationPublisherAttribute("singularity.microsoft.com")]
|
||
|
[assembly: AssertPrivilegeAttribute("$register-privilege.localhost")]
|
||
|
|
||
|
namespace Microsoft.Singularity.Services.CounterProxy
|
||
|
{
|
||
|
[Category("Service")]
|
||
|
internal sealed class Parameters
|
||
|
{
|
||
|
[Endpoint]
|
||
|
public readonly TRef<ManagedServiceContract.Exp:Start> serviceRef;
|
||
|
|
||
|
[Endpoint]
|
||
|
public readonly TRef<DirectoryServiceContract.Imp:Ready> directoryRef;
|
||
|
|
||
|
[Endpoint]
|
||
|
public readonly TRef<DirectoryServiceContract.Exp:Start> myDSRef;
|
||
|
|
||
|
[Endpoint]
|
||
|
public readonly TRef<ManagedProxyContract.Imp:Start> proxyRef;
|
||
|
|
||
|
reflective private Parameters();
|
||
|
}
|
||
|
|
||
|
internal class CounterJournalProducer : JournalProducer
|
||
|
{
|
||
|
internal CounterJournalProducer() : base() {}
|
||
|
|
||
|
protected override bool Accept(ServiceContract.Exp:Start! ep)
|
||
|
{
|
||
|
// ep must be a type of CounterContract.Exp
|
||
|
CounterContract.Exp:Start cep = ep as CounterContract.Exp:Start;
|
||
|
return (cep != null);
|
||
|
}
|
||
|
|
||
|
protected override void Substitute([Claims]ServiceContract.Exp:Start! ep, out ServiceContract.Exp! newEp)
|
||
|
{
|
||
|
Journalet! journalet;
|
||
|
ServiceContract.Exp:Start! serverEp;
|
||
|
|
||
|
journalet = new CounterJournalet(this, ep);
|
||
|
journalet.CreateServerEndpoint(out serverEp);
|
||
|
journalet.Start();
|
||
|
RegisterJournalet(journalet);
|
||
|
newEp = serverEp;
|
||
|
}
|
||
|
|
||
|
internal static int AppMain(Parameters! config)
|
||
|
{
|
||
|
ManagedServiceContract.Exp:Start ep;
|
||
|
DirectoryServiceContract.Imp:Ready dep;
|
||
|
DirectoryServiceContract.Exp:Start fep;
|
||
|
ManagedProxyContract.Imp:Start mep;
|
||
|
|
||
|
dep = config.directoryRef.Acquire();
|
||
|
ep = config.serviceRef.Acquire();
|
||
|
fep = config.myDSRef.Acquire();
|
||
|
mep = config.proxyRef.Acquire();
|
||
|
if (ep == null || dep == null || fep == null || mep == null) {
|
||
|
delete ep;
|
||
|
delete dep;
|
||
|
delete fep;
|
||
|
delete mep;
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
JournalProducer! jp = new CounterJournalProducer();
|
||
|
try {
|
||
|
jp.Start(ep, dep, fep, mep);
|
||
|
}
|
||
|
catch (Exception e) {
|
||
|
DebugStub.WriteLine(e.ToString());
|
||
|
DebugStub.WriteLine(e.StackTrace);
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
}
|