 |
Changeset 2448
- Timestamp:
- 07/12/07 00:44:41
(1 year ago)
- Author:
- kris
- Message:
Added Tom's magic wrappers
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r2442 |
r2448 |
|
| 3 | 3 | *******************************************************************************/ |
|---|
| 4 | 4 | |
|---|
| 5 | | private import tango.net.cluster.NetworkCall; |
|---|
| | 5 | public import tango.net.cluster.NetworkCall; |
|---|
| | 6 | |
|---|
| 6 | 7 | |
|---|
| 7 | 8 | /******************************************************************************* |
|---|
| | 9 | |
|---|
| | 10 | a Task function |
|---|
| | 11 | |
|---|
| | 12 | *******************************************************************************/ |
|---|
| | 13 | |
|---|
| | 14 | real multiply (real x, real y) |
|---|
| | 15 | { |
|---|
| | 16 | return x * y; |
|---|
| | 17 | } |
|---|
| | 18 | |
|---|
| | 19 | |
|---|
| | 20 | /******************************************************************************* |
|---|
| | 21 | |
|---|
| | 22 | a Task function |
|---|
| | 23 | |
|---|
| | 24 | *******************************************************************************/ |
|---|
| | 25 | |
|---|
| | 26 | int divide (int x, int y) |
|---|
| | 27 | { |
|---|
| | 28 | return x / y; |
|---|
| | 29 | } |
|---|
| | 30 | |
|---|
| | 31 | |
|---|
| | 32 | /******************************************************************************* |
|---|
| | 33 | |
|---|
| | 34 | a verbose Task message |
|---|
| 8 | 35 | |
|---|
| 9 | 36 | *******************************************************************************/ |
|---|
| … | … | |
| 28 | 55 | } |
|---|
| 29 | 56 | |
|---|
| 30 | | override void read (IReader input) {input (a) (b) (result);} |
|---|
| | 57 | override void read (IReader input) {input (a)(b)(result);} |
|---|
| 31 | 58 | |
|---|
| 32 | | override void write (IWriter output) {output (a) (b) (result);} |
|---|
| | 59 | override void write (IWriter output) {output (a)(b)(result);} |
|---|
| 33 | 60 | } |
|---|
| r2445 |
r2448 |
|
| 21 | 21 | void main (char[][] args) |
|---|
| 22 | 22 | { |
|---|
| 23 | | StopWatch w; |
|---|
| 24 | | |
|---|
| 25 | 23 | auto cluster = (new Cluster).join; |
|---|
| 26 | 24 | auto channel = cluster.createChannel ("rpc.channel"); |
|---|
| 27 | 25 | |
|---|
| | 26 | // an explicit task instance |
|---|
| 28 | 27 | auto add = new Add; |
|---|
| | 28 | |
|---|
| | 29 | // an implicit task instance |
|---|
| | 30 | auto mul = new NetCall!(multiply); |
|---|
| | 31 | |
|---|
| | 32 | StopWatch w; |
|---|
| 29 | 33 | while (true) |
|---|
| 30 | 34 | { |
|---|
| 31 | 35 | w.start; |
|---|
| 32 | | for (int i=20000; i--;) |
|---|
| 33 | | add (1, 2, channel); |
|---|
| 34 | | |
|---|
| | 36 | for (int i=10000; i--;) |
|---|
| | 37 | { |
|---|
| | 38 | // both tasks are used in the same manner |
|---|
| | 39 | add (1, 2, channel); |
|---|
| | 40 | mul (1, 2, channel); |
|---|
| | 41 | } |
|---|
| 35 | 42 | Stdout.formatln ("{} calls/s", 20000/w.stop); |
|---|
| 36 | 43 | } |
|---|
| r2442 |
r2448 |
|
| 29 | 29 | auto server = new TaskServer (new InternetAddress(arg.port), arg.log); |
|---|
| 30 | 30 | server.enroll (new Add); |
|---|
| | 31 | server.enroll (new NetCall!(multiply)); |
|---|
| 31 | 32 | server.start; |
|---|
| 32 | 33 | } |
|---|
Download in other formats:
|
 |
 |
|
 |
Copyright © 2006-2008 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic