• Keine Ergebnisse gefunden

Cooperative Tasks

N/A
N/A
Protected

Academic year: 2022

Aktie "Cooperative Tasks"

Copied!
23
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

JCoBox: Java + Asynchronously Communicating Object Groups with

Cooperative Tasks

Jan Sch ¨afer Arnd Poetzsch-Heffter

June 26, 2012

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 1

(2)

Challenge

Model for concurrent and distributed OO-programming that

is simpler for programmers

is a better basis for reasoning

scales from local concurrency to distributed programming

integrates well with classical sequential OOP, in particular:

I Synchronous methods calls and asynchronous messages

I Smooth language integration

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 2

(3)

Idea

CoBoxes = Active Objects + Groups of objects

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 3

(4)

Related Work

Creol (∼CoBoxes of size 1)

ASP (active object heaps with a single access object)

E-Programming Language (VATs∼CoBoxes)

AmbientTalk (∼ASP+channels)

Sing# (processes + channels with contracts)

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 4

(5)

Outline

Concepts and Approach

JCoBox: The Language

Implementation

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 5

(6)

Actors

1

/ Active Objects

2

1Gul Agha, 1986

2Denis Caromel, 1993

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 6

(7)

Creol

3

3Einar Broch Johnsen et al, 2006

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 7

(8)

ASP

4

4Denis Caromel, 2004

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 8

(9)

CoBoxes

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 9

(10)

Groups of Objects

Reasons for regions

State encapsulation / modularity (ownership types5)

Region-based memory management

Distribution

Synchronization

How boxes are defined

Created by designated classes (@CoBox class C ...)

Other objects are created local to the box of the creator

5e.g. Clarke et al, 1998

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 10

(11)

Multiple Port Objects

OO-runtime components have multiple objects at the boundary:

Examples

Linked List (Iterators)

XML-DOM (Document→Elements→Attributes)

GUIs (Frame→Toolbar→Buttons)

Synchronization of concurrent sessions

COM/OSGi: exposed services

. . .

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 11

(12)

Example: List

interface List{

Iterator getIterator();

...

}

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 12

(13)

Example: XML-DOM

interface DOM{

Document getDocument();

...

}

interface Document{

Element getDocumentElement();

...

}

interface Element{

Attribute getAttribute(String name);

}

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 13

(14)

Concepts and Approach

JCoBox: The Language

Implementation

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 14

(15)

JCoBox: Sequential Java + CoBoxes

Sequential Java

CoBox classes: @CoBox class ...

Asynchronous method calls: x!m()

Futures: Fut<T>f;

Cooperative tasks:

I blocking:f.get

I suspension:f.await,yield

a.m()≡a!m().get

Transfer objects: @Transfer class ...

Immutable objects: @Immutable class ...

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 15

(16)

Example: Simple Chat Application

Server Session

Session Client

Client GUI

GUI

interface Client4Session{ void onChatMsg(Msg m);

}

interface Client4GUI{

void publishMsg(String m);

}

interface Server{

Session connect(Client c);

}

interface Session{ void publish(Msg m);

void close();

}

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 16

(17)

Example: Server Class

@CoBox

class ChatClientimplementsClient4Session, Client4GUI{ GUI gui = new GUI(this); Session session; String userName;

ChatClient(String name, Server s){ userName = name;

gui!init(userName);

Fut<Session>sessFut = s!connect(userName,this);

session = sessFut.await();

}

publicvoid onChatMsg(Msg m){

gui!showString(m.user+”: ”+m.content);

}

publicvoid publishMsg(String s){ if( session !=null) session!publish(s);

} }

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 17

(18)

Example: Server Class

@CoBox

class ChatServerimplementsServer{

List<ChatSession>sessions = new ArrayList<ChatSession>();

publicSession connect(String userName, Client4Session c) throwsUserAlreadyExists{ checkUserName(userName);

ChatSession s = new ChatSession(this,userName,c);

sessions.add(s);

return s;

}

void checkUserName(String userName)throws...{ ...

} }

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 18

(19)

Example: Session Class

class ChatSessionimplementsSession{ privateChatServer server;

privateClient4Session client;

String userName;

privateboolean isClosed =false;

ChatSession(ChatServer s, String uNm, Client4Session c){...} publicvoid publish(String msg){

if(isClosed)thrownew DisconnectedException();

Msg msgx = new Msg(userName,msg);

for(ChatSession s : server.sessions){ s.client!onChatMsg(msgx);

} }

publicvoid close(){...} }

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 19

(20)

Example: Transfer Class

@Transfer class Msg{

String user;

String content;

Msg(String user, String content){ this.user = user; this.content = content;

} }

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 20

(21)

Concepts and Approach

JCoBox: The Language

Implementation

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 21

(22)

Implementation

Language and Compiler

based on Polyglot 1.3.5

support for Java 5

CoBoxes

represented by a cobox object

objects have an additional field referencing their cobox

objects of transfer or immutable classes have no such field

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 22

(23)

Method calls

Asynchronous calls are wrapped into special task objects that also deal with parameter transfer

Simple optimizations aviod that unnessary futures are created

Where possible, synchronous calls are treated as normal method calls

Task scheduling

The tasks of a cobox are handled by a FIFO scheduler.

Asynchronous calls (task objects) are executed by a thread pool.

Jan Sch ¨afer, Arnd Poetzsch-Heffter JCoBox 23

Referenzen

ÄHNLICHE DOKUMENTE

The eight remaining buttons allow you to perform the following functions: display the error log, trap log, and state change log; create a network; graphically represent the status

MICRO CRAFT CORPORATION MAKES NO WARRANTIES, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS MANUAL OR WITH RESPECT TO THE SOFTWARE DESCRIBED IN THIS MANUAL,

Two types of disk data files can be created and accessed by a UNIBASIC program; sequential access files and random access files.. Both types of files are

Depending on the cellular context and receptor species (apparent affinity of human EPO for huEPOR was about three times as high as that for rodent EPOR), EPO bound at 10 to 200

In the aftermath of any agreement, the United States (and the international community) must also maintain the will and capability to take effec- tive action, including the use

When you copy the VP Expert Common Software file to the ViewPoint Application Loader icon, Expert is product factored to the workstation.. Therefore, you cannot

When not keeping to the same rules, those who followed the DE or the SF rule in 3-menus tend to be- come Naive when choosing among 6-menus. The higher number of subjects being

It might be that “too much choice” worked towards negat- ing the common standard effect, either because it made it more difficult for consumers to identify offers that were expressed