 George Chrysanthakopoulos Software Architect Microsoft Corporation    Initially applied in robotics     

Download Report

Transcript  George Chrysanthakopoulos Software Architect Microsoft Corporation    Initially applied in robotics     

 George Chrysanthakopoulos
Software Architect
Microsoft Corporation



Initially applied in robotics





Runtime
• Coordination and
Concurrency runtime
(CCR)
• Decentralized
Software Services
(DSS)
Authoring Tools
• Visual Programming
Language
• Visual Configuration
and Deployment
• Visual Studio
templates
Services
• Samples and tutorials
• Infrastructure
services
Beyond robotics!
ASP.NET page handling,
IO coordination
Event processing
for security systems
Mail sorting system

C




C




R


Siemens Automation






Siemens case study quotes


Tyco






Tyco case study quotes











Post places a message
on the port
Port
Dispatcher schedules items
from its queues round-robin
to run in its threads
Enqueue work item Dispatcher
Scheduler picks next
work item to execute
Arbiter is activated on queue
Thread calls handler
with message as arg
Creates work item from
message and handler
Arbiter checks whether it
can consume the message
Arbiter
Handler
Arbiter is attached to port
Dispatcher Threads
Queues
There can be many of everything
Port
Dispatcher
Arbiter
Handler
Handler
Handler
Dispatcher Threads
Queues
Exposed via Arbiter methods
Code-Scheduling
(non port-specific)
Single-Port
Primitives
Multi-Port
Primitives
Dispatcher uses fixed
number of threads,
schedules from queues
in round-robin
var dispatcher = new Dispatcher(0,”default”);
Port: Building block for
var queue = new DispatcherQueue(dispatcher);
sending and receiving
var port = new Port<string>();
messages
port.Post("Hello, World!");
Post: Queues a message
Arbiter.Activate(queue,
port.Receive(message => Console.WriteLine(message)
)
);
Receive coordination
primitive
Port on which to
receive the message
Task: Delegate that
handles the message
(message is consumed)
Iterator version
void Start()
{
var queue = new DispatcherQueue();
Lambda captures
var port = new Port<string>();
arguments for iterator
port.Post("Hello"); port.Post(“World”);
Arbiter.Activate(queue,
new IterativeTask(() => Hello(port) )
Loops around
);
asynchronous
Schedule iterative task
}
operations are easy
IEnumerator<ITask> Hello(Port<string> port)
Yield execution until
{
receive is satisfied
for(var i=0; i<5; i++)
{
yield return port.Receive();
var message = (string)port;
Item retrieved
Console.WriteLine(message);
after yield
}
Asynchronous Pattern (Begin/End)
IEnumerator<ITask> CcrReadFileAsync(string file)
{
Instead of passing a
var result = new Port<IAsyncResult>(); delegate, stream will post
using (var fs = new
AR to port
FileStream(file,…,FileOptions.Asynchronous))
{
var buf = new byte[fs.Length];
fs.BeginRead(buf, 0, buf.Length, result.Post, null);
yield return result.Receive();
var ar = (IAsyncResult)resultPort.Test();
try
{
fs.EndRead(ar);
Retrieve AR result from port
ProcessData(buf);
}
catch { // handle exception }
Complete operation
}
}
Using adapters for common APIs
static IEnumerator<ITask> CopyStream(Stream source, Stream dest)
{
var buffer = new byte[4096];
CCR Adapter for
int read = 0;
Stream class
do
{
PortSet<int,Exception> readResult = StreamAdapter.Read(
source, buffer, 0, buffer.Length);
yield return readResult.Choice();
var exception = (Exception)readResult;
Yield to result
if (exception != null)
outcomes
yield break;
read = (int)readResult;
Retrieve success
var writeResult = StreamAdapter.Write(buffer,0,read);
outcome (bytes read)
yield return writeResult.Choice();
} while (…)
}
Proceed to
asynchronous write











Structured Data Manipulation –
INSERT, UPDATE, …
Events represent state changes
Application graph observable
Simple, uniform APIs – GET, POST, …
UI Separated from
Implementation
Session-less
Microsoft Open Specification Promise
<DriveState
<Connected>true</Connected>
<DistanceBetweenWheels>0.112</DistanceBetweenWheels>
<LeftWheel>
…
</LeftWheel>
<RightWheel>
…
</RightWheel>
<PollingFrequencyMs>80</PollingFrequencyMs>
<TimeStamp>2007-10-10T13:07:45.5195866-07:00</TimeStamp>
</DriveState>
Service Orchestration
Flexible UI









Define Data Types
Define Service Types
Implement Service
• DATA AND
MESSAGE CONTRACTS
• MESSAGE-OPERATIONS
• PARTNERSHIPS
• POLICIES
• MESSAGE HANDLERS
• STATE AND PUB-SUB
• STATE NOTIFICATIONS
Deploy And
Run Application
Compose Application
Build Service
• DECLARE
• DRAW
• CODE
• VPL TOOL
• PROXY GENERATION
• VPL TOOLS
• DSS-HOSTED
• SELF-HOSTED
Example state and operation types
[DataContract]
class State
{
[DataMember]
public List<Record> {get; set;}
}
[DataContract]
class Record
{
[DataMember]
public string Name {get; set;}
[DataMember]
public int Age{get; set;}
}
// operation
class Query : Query<Record,Record>{}
// operation port
class OperationsPort : PortSet<Query,Get,Update> {}
Declare partnerships, operation port
[Contract(Contract.Identifier)]
Declarative, dynamic
class RecordKeeperService : DsspServiceBase composition, annotations
{
picked up by visual editor
[Partner(“PeopleLookup”,
Policy = PartnerCreationPolicy.UseExistingOrCreate,
Optional = false)]
peopleLookup.OperationsPort _peopleLookupPort =
peopleLookup.OperationsPort();
[ServicePort(“/recordkeeper”,AllowMultipleInstances = true]
OperationsPort _mainPort;
protected override void Start()
{
base.Start();
}
}
Attach handlers to operation
port, publish instance URI in
service directory
Typical service handlers
[ServiceHandler(ServiceHandlerBehavior.Concurrent)]
public IEnumerator<ITask> QueryHandler(Query queryOp)
{
var response = FindItem(queryOp.Body);
queryOp.ResponsePort.Post(response);
yield break;
}
CCR Interleave is iterator-aware,
guaranteeing atomicity across
[ServiceHandler(ServiceHandlerBehavior.Exclusive)]
asynchronous steps
public IEnumerator<ITask> UpdateHandler(Update updateOp)
{
QueryAge queryAgeOp;
yield return _peopleLookupPort.Query(out queryAgeOp);
int age = (int) queryAgeOp.ResponsePort;
UpdateRecord(age, updateOp.Body.Name);
updateOp.ResponsePort.Post(new UpdateResponse());
}
Causalities
Create causality at root
of execution graph
Deal with error as
message at origin
of execution
Failure occurs on one
of the side branches

Orchestrating DSS services with dataflow




Notification



Available DSS services
Service instance
Request
Response
Building applications from components







Distributed applications











http://www.microsoft.com/ccrdss





www.microsoftpdc.com
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market
conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation.
MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.