diff options
author | Alexander Kriegisch <Alexander@Kriegisch.name> | 2024-02-01 08:57:52 +0700 |
---|---|---|
committer | Alexander Kriegisch <Alexander@Kriegisch.name> | 2024-02-01 08:58:28 +0700 |
commit | 983159c76ca8163b61f0d52c98522e8bc113f585 (patch) | |
tree | 3137bb04a0942b59d7b066912a2fa8fed5601373 /docs/modules/ROOT/pages/examples/telecom | |
parent | c99b58736fd7f2952fe9bf787333631a762dcbeb (diff) | |
download | aspectj-antora.tar.gz aspectj-antora.zip |
Move source code examples to Antora examples directoryantora
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Diffstat (limited to 'docs/modules/ROOT/pages/examples/telecom')
16 files changed, 0 insertions, 776 deletions
diff --git a/docs/modules/ROOT/pages/examples/telecom/AbstractSimulation.java b/docs/modules/ROOT/pages/examples/telecom/AbstractSimulation.java deleted file mode 100644 index 1c44af7a7..000000000 --- a/docs/modules/ROOT/pages/examples/telecom/AbstractSimulation.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - -Copyright (c) Xerox Corporation 1998-2002. All rights reserved. - -Use and copying of this software and preparation of derivative works based -upon this software are permitted. Any distribution of this software or -derivative works must comply with all applicable United States export control -laws. - -This software is made available AS IS, and Xerox Corporation makes no warranty -about the software, its performance or its conformity to any specification. - -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| - -*/ -package telecom; - -public abstract class AbstractSimulation { - - public static AbstractSimulation simulation; - - /** - * Creates objects and puts them to work. - */ - public void run() { - Customer jim = new Customer("Jim", 650); - Customer mik = new Customer("Mik", 650); - Customer crista = new Customer("Crista", 415); - - say("jim calls mik..."); - Call c1 = jim.call(mik); - wait(1.0); - say("mik accepts..."); - mik.pickup(c1); - wait(2.0); - say("jim hangs up..."); - jim.hangup(c1); - report(jim); - report(mik); - report(crista); - - say("mik calls crista..."); - Call c2 = mik.call(crista); - say("crista accepts..."); - crista.pickup(c2); - wait(1.5); - say("crista hangs up..."); - crista.hangup(c2); - report(jim); - report(mik); - report(crista); - } - - /** - * Print a report of the connection time for customer - */ - abstract protected void report(Customer c); - - /** - * Wait 0.1 seconds per "second" for simulation - */ - protected static void wait(double seconds) { - Object dummy = new Object(); - synchronized (dummy) { - //XXX cheat and only wait 0.1 seconds per second - try {dummy.wait((long)(seconds*100)); } - catch (Exception e) {} - } - } - - /** - * Put a message on standard output - */ - protected static void say(String s){ - System.out.println(s); - } - -} diff --git a/docs/modules/ROOT/pages/examples/telecom/BasicSimulation.java b/docs/modules/ROOT/pages/examples/telecom/BasicSimulation.java deleted file mode 100644 index ab7426376..000000000 --- a/docs/modules/ROOT/pages/examples/telecom/BasicSimulation.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - -Copyright (c) Xerox Corporation 1998-2002. All rights reserved. - -Use and copying of this software and preparation of derivative works based -upon this software are permitted. Any distribution of this software or -derivative works must comply with all applicable United States export control -laws. - -This software is made available AS IS, and Xerox Corporation makes no warranty -about the software, its performance or its conformity to any specification. - -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| - -*/ -package telecom; - -/** - * This simulation subclass implements AbstractSimulation.run(..) - * with a test script for the telecom system with only the - * basic objects. - */ -public class BasicSimulation extends AbstractSimulation { - - public static void main(String[] args){ - simulation = new BasicSimulation(); - simulation.run(); - } - - protected void report(Customer c) { } - -} diff --git a/docs/modules/ROOT/pages/examples/telecom/Billing.java b/docs/modules/ROOT/pages/examples/telecom/Billing.java deleted file mode 100644 index 651d64b36..000000000 --- a/docs/modules/ROOT/pages/examples/telecom/Billing.java +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright (c) Xerox Corporation 1998-2002. All rights reserved. - -Use and copying of this software and preparation of derivative works based -upon this software are permitted. Any distribution of this software or -derivative works must comply with all applicable United States export control -laws. - -This software is made available AS IS, and Xerox Corporation makes no warranty -about the software, its performance or its conformity to any specification. -*/ - -package telecom; -/** - * The Billing aspect deals with... billing. - * How much money did each connection cost? - * How much money did each call cost? - * How much money is being debited to a customer? - * This aspect can be used by other parts of the system. (not in this example) - * - * Billing can depend many things, such as timing, the type of the connection, - * some special discounts the customer has, special features, etc. In here, - * it depends only on timing and on the type of the connection. - */ -public aspect Billing { - // precedence required to get advice on endtiming in the right order - declare precedence: Billing, Timing; - - public static final long LOCAL_RATE = 3; - public static final long LONG_DISTANCE_RATE = 10; - - public Customer Connection.payer; - public Customer getPayer(Connection conn) { return conn.payer; } - /** - * Caller pays for the call - */ - after(Customer cust) returning (Connection conn): - args(cust, ..) && call(Connection+.new(..)) { - conn.payer = cust; - } - - /** - * Connections give the appropriate call rate - */ - public abstract long Connection.callRate(); - - - public long LongDistance.callRate() { return LONG_DISTANCE_RATE; } - public long Local.callRate() { return LOCAL_RATE; } - - - /** - * When timing stops, calculate and add the charge from the - * connection time - */ - after(Connection conn): Timing.endTiming(conn) { - long time = Timing.aspectOf().getTimer(conn).getTime(); - long rate = conn.callRate(); - long cost = rate * time; - getPayer(conn).addCharge(cost); - } - - - /** - * Customers have a bill paying aspect with state - */ - public long Customer.totalCharge = 0; - public long getTotalCharge(Customer cust) { return cust.totalCharge; } - - public void Customer.addCharge(long charge){ - totalCharge += charge; - } -} diff --git a/docs/modules/ROOT/pages/examples/telecom/BillingSimulation.java b/docs/modules/ROOT/pages/examples/telecom/BillingSimulation.java deleted file mode 100644 index 09f273ff6..000000000 --- a/docs/modules/ROOT/pages/examples/telecom/BillingSimulation.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - -Copyright (c) Xerox Corporation 1998-2002. All rights reserved. - -Use and copying of this software and preparation of derivative works based -upon this software are permitted. Any distribution of this software or -derivative works must comply with all applicable United States export control -laws. - -This software is made available AS IS, and Xerox Corporation makes no warranty -about the software, its performance or its conformity to any specification. - -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| - -*/ -package telecom; - -/** - * This simulation subclass implements AbstractSimulation.report(..) - * - */ -public class BillingSimulation extends AbstractSimulation { - - public static void main(String[] args){ - System.out.println("\n... Billing simulation 2 ...\n"); - simulation = new BillingSimulation(); - simulation.run(); - } - - /** - * Print a report of the connection time and the bill for customer - */ - protected void report(Customer c){ - Timing t = Timing.aspectOf(); - Billing b = Billing.aspectOf(); - System.out.println(c + " has been connected for " - + t.getTotalConnectTime(c) - + " seconds and has a bill of " - + b.getTotalCharge(c)); - } -} - diff --git a/docs/modules/ROOT/pages/examples/telecom/Call.java b/docs/modules/ROOT/pages/examples/telecom/Call.java deleted file mode 100644 index 3d3489e86..000000000 --- a/docs/modules/ROOT/pages/examples/telecom/Call.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - -Copyright (c) Xerox Corporation 1998-2002. All rights reserved. - -Use and copying of this software and preparation of derivative works based -upon this software are permitted. Any distribution of this software or -derivative works must comply with all applicable United States export control -laws. - -This software is made available AS IS, and Xerox Corporation makes no warranty -about the software, its performance or its conformity to any specification. - -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| - -*/ -package telecom; -import java.util.Vector; -import java.util.Enumeration; - -/** - * A call supports the process of a customer trying to - * connect to others. - */ -public class Call { - - private Customer caller, receiver; - private Vector connections = new Vector(); - - /** - * Create a new call connecting caller to receiver - * with a new connection. This should really only be - * called by Customer.call(..) - */ - public Call(Customer caller, Customer receiver) { - this.caller = caller; - this.receiver = receiver; - Connection c; - if (receiver.localTo(caller)) { - c = new Local(caller, receiver); - } else { - c = new LongDistance(caller, receiver); - } - connections.addElement(c); - } - - /** - * picking up a call completes the current connection - * (this means that you shouldnt merge calls until - * they are completed) - */ - public void pickup() { - Connection connection = (Connection)connections.lastElement(); - connection.complete(); - } - - - /** - * Is the call in a connected state? - */ - public boolean isConnected(){ - return ((Connection)connections.lastElement()).getState() - == Connection.COMPLETE; - } - - /** - * hanging up a call drops the connection - */ - public void hangup(Customer c) { - for(Enumeration e = connections.elements(); e.hasMoreElements();) { - ((Connection)e.nextElement()).drop(); - } - } - - /** - * is Customer c one of the customers in this call? - */ - public boolean includes(Customer c){ - boolean result = false; - for(Enumeration e = connections.elements(); e.hasMoreElements();) { - result = result || ((Connection)e.nextElement()).connects(c); - } - return result; - } - - /** - * Merge all connections from call 'other' into 'this' - */ - public void merge(Call other){ - for(Enumeration e = other.connections.elements(); e.hasMoreElements();){ - Connection conn = (Connection)e.nextElement(); - other.connections.removeElement(conn); - connections.addElement(conn); - } - } -} diff --git a/docs/modules/ROOT/pages/examples/telecom/Connection.java b/docs/modules/ROOT/pages/examples/telecom/Connection.java deleted file mode 100644 index 7d54ec843..000000000 --- a/docs/modules/ROOT/pages/examples/telecom/Connection.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - -Copyright (c) Xerox Corporation 1998-2002. All rights reserved. - -Use and copying of this software and preparation of derivative works based -upon this software are permitted. Any distribution of this software or -derivative works must comply with all applicable United States export control -laws. - -This software is made available AS IS, and Xerox Corporation makes no warranty -about the software, its performance or its conformity to any specification. - -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| - -*/ -package telecom; - -/** - * Connections are circuits between customers - * There are two kinds: local and long distance - * see subclasses at the end of this file. - */ -public abstract class Connection { - - public static final int PENDING = 0; - public static final int COMPLETE = 1; - public static final int DROPPED = 2; - - Customer caller, receiver; - private int state = PENDING; - - /** - * Creatte a new Connection between a and b - */ - Connection(Customer a, Customer b) { - this.caller = a; - this.receiver = b; - } - - /** - * what is the state of the connection? - */ - public int getState(){ - return state; - } - - /** - * get the customer who initiated this connection - */ - public Customer getCaller() { return caller; } - - /** - * get the customer who received this connection - */ - public Customer getReceiver() { return receiver; } - - /** - * Called when a call is picked up. This means the b side has picked up - * and the connection should now complete itself and start passing data. - */ - void complete() { - state = COMPLETE; - System.out.println("connection completed"); - } - - /** - * Called when the connection is dropped from a call. Is intended to - * free up any resources the connection was consuming. - */ - void drop() { - state = DROPPED; - System.out.println("connection dropped"); - } - - /** - * Is customer c connected by this connection? - */ - public boolean connects(Customer c){ - return (caller == c || receiver == c); - } - -} - - - diff --git a/docs/modules/ROOT/pages/examples/telecom/Customer.java b/docs/modules/ROOT/pages/examples/telecom/Customer.java deleted file mode 100644 index 1e099984c..000000000 --- a/docs/modules/ROOT/pages/examples/telecom/Customer.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - -Copyright (c) Xerox Corporation 1998-2002. All rights reserved. - -Use and copying of this software and preparation of derivative works based -upon this software are permitted. Any distribution of this software or -derivative works must comply with all applicable United States export control -laws. - -This software is made available AS IS, and Xerox Corporation makes no warranty -about the software, its performance or its conformity to any specification. - -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| - -*/ -package telecom; -import java.util.Vector; - -/** - * Customers have a unique id (name in this case for didactic purposes - * but it could be telephone number) and area code. - * They also have protocol for managing calls: call, pickup, etc. - */ -public class Customer { - - private String name; - private int areacode; - private Vector calls = new Vector(); - - /** - * unregister a call - */ - protected void removeCall(Call c){ - calls.removeElement(c); - } - - /** - * register a call - */ - protected void addCall(Call c){ - calls.addElement(c); - } - - /** - * Make a new customer with given name - */ - public Customer(String name, int areacode) { - this.name = name; - this.areacode = areacode; - } - - /** - * String rendition of customer - */ - public String toString() { - return name + "(" + areacode + ")"; - } - - /** - * what area is the customer in? - */ - public int getAreacode(){ - return areacode; - } - - /** - * Is the other customer in the same area? - */ - public boolean localTo(Customer other){ - return areacode == other.areacode; - } - - /** - * Make a new call to receiver - */ - public Call call(Customer receiver) { - Call call = new Call(this, receiver); - addCall(call); - return call; - } - - /** - * pick up a call - */ - public void pickup(Call call) { - call.pickup(); - addCall(call); - } - - /** - * hang up a call - */ - public void hangup(Call call) { - call.hangup(this); - removeCall(call); - } - - /** - * Merge a pair of calls -- conference them - * PRE: call1.includes(this) - * call2.includes(this) - * call1.connected() - * call2.connected() - * POST: call1 includes all customers connected by call1@pre and call2@pre - */ - public void merge(Call call1, Call call2){ - call1.merge(call2); - removeCall(call2); - } -} diff --git a/docs/modules/ROOT/pages/examples/telecom/Local.java b/docs/modules/ROOT/pages/examples/telecom/Local.java deleted file mode 100644 index e0bc02679..000000000 --- a/docs/modules/ROOT/pages/examples/telecom/Local.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - -Copyright (c) Xerox Corporation 1998-2002. All rights reserved. - -Use and copying of this software and preparation of derivative works based -upon this software are permitted. Any distribution of this software or -derivative works must comply with all applicable United States export control -laws. - -This software is made available AS IS, and Xerox Corporation makes no warranty -about the software, its performance or its conformity to any specification. - -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| - -*/ -package telecom; - -public class Local extends Connection { - Local(Customer a, Customer b) { - super(a, b); - System.out.println("[new local connection from " + - a + " to " + b + "]"); - } -} diff --git a/docs/modules/ROOT/pages/examples/telecom/LongDistance.java b/docs/modules/ROOT/pages/examples/telecom/LongDistance.java deleted file mode 100644 index b2ed6eb7d..000000000 --- a/docs/modules/ROOT/pages/examples/telecom/LongDistance.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - -Copyright (c) Xerox Corporation 1998-2002. All rights reserved. - -Use and copying of this software and preparation of derivative works based -upon this software are permitted. Any distribution of this software or -derivative works must comply with all applicable United States export control -laws. - -This software is made available AS IS, and Xerox Corporation makes no warranty -about the software, its performance or its conformity to any specification. - -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| - -*/ -package telecom; - -public class LongDistance extends Connection { - LongDistance(Customer a, Customer b) { - super(a, b); - System.out.println("[new long distance connection from " + - a + " to " + b + "]"); - } -} diff --git a/docs/modules/ROOT/pages/examples/telecom/Timer.java b/docs/modules/ROOT/pages/examples/telecom/Timer.java deleted file mode 100644 index 813ae3a0d..000000000 --- a/docs/modules/ROOT/pages/examples/telecom/Timer.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - -Copyright (c) Xerox Corporation 1998-2002. All rights reserved. - -Use and copying of this software and preparation of derivative works based -upon this software are permitted. Any distribution of this software or -derivative works must comply with all applicable United States export control -laws. - -This software is made available AS IS, and Xerox Corporation makes no warranty -about the software, its performance or its conformity to any specification. - -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| - -*/ -package telecom; - - -/** - * Simple timer machine used to record elapsed time - */ -public class Timer { - public long startTime, stopTime; - - /** - * set the start time - */ - public void start() { - startTime = System.currentTimeMillis(); - stopTime = startTime; - } - - /** - * set the end time - */ - public void stop() { - stopTime = System.currentTimeMillis(); - } - - /** - * set how much time passed between last start and stop? - */ - public long getTime() { - return stopTime - startTime; - } -} - - diff --git a/docs/modules/ROOT/pages/examples/telecom/TimerLog.java b/docs/modules/ROOT/pages/examples/telecom/TimerLog.java deleted file mode 100644 index c736625b5..000000000 --- a/docs/modules/ROOT/pages/examples/telecom/TimerLog.java +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright (c) Xerox Corporation 1998-2002. All rights reserved. - -Use and copying of this software and preparation of derivative works based -upon this software are permitted. Any distribution of this software or -derivative works must comply with all applicable United States export control -laws. - -This software is made available AS IS, and Xerox Corporation makes no warranty -about the software, its performance or its conformity to any specification. -*/ -package telecom; - -public aspect TimerLog { - - after(Timer t): target(t) && call(* Timer.start()) { - System.err.println("Timer started: " + t.startTime); - } - - after(Timer t): target(t) && call(* Timer.stop()) { - System.err.println("Timer stopped: " + t.stopTime); - } -} diff --git a/docs/modules/ROOT/pages/examples/telecom/Timing.java b/docs/modules/ROOT/pages/examples/telecom/Timing.java deleted file mode 100644 index 29eba02ea..000000000 --- a/docs/modules/ROOT/pages/examples/telecom/Timing.java +++ /dev/null @@ -1,57 +0,0 @@ -/* -Copyright (c) Xerox Corporation 1998-2002. All rights reserved. - -Use and copying of this software and preparation of derivative works based -upon this software are permitted. Any distribution of this software or -derivative works must comply with all applicable United States export control -laws. - -This software is made available AS IS, and Xerox Corporation makes no warranty -about the software, its performance or its conformity to any specification. -*/ - -package telecom; - -/** - * The Timing aspect is concerned with the duration - * of connections and with customer's cumulative - * connection time. - */ -public aspect Timing { - - /** - * Every Customer has a total connection time - */ - public long Customer.totalConnectTime = 0; - - public long getTotalConnectTime(Customer cust) { - return cust.totalConnectTime; - } - /** - * Every connection has a timer - */ - private Timer Connection.timer = new Timer(); - public Timer getTimer(Connection conn) { return conn.timer; } - - /** - * Start the timer when call completed - */ - after (Connection c): target(c) && call(void Connection.complete()) { - getTimer(c).start(); - } - - /** - * When to stop the timer - */ - pointcut endTiming(Connection c): target(c) && - call(void Connection.drop()); - - /** - * Stop the timer when call dropped and update the involved parties - */ - after(Connection c): endTiming(c) { - getTimer(c).stop(); - c.getCaller().totalConnectTime += getTimer(c).getTime(); - c.getReceiver().totalConnectTime += getTimer(c).getTime(); - } -} diff --git a/docs/modules/ROOT/pages/examples/telecom/TimingSimulation.java b/docs/modules/ROOT/pages/examples/telecom/TimingSimulation.java deleted file mode 100644 index 309563769..000000000 --- a/docs/modules/ROOT/pages/examples/telecom/TimingSimulation.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - -Copyright (c) Xerox Corporation 1998-2002. All rights reserved. - -Use and copying of this software and preparation of derivative works based -upon this software are permitted. Any distribution of this software or -derivative works must comply with all applicable United States export control -laws. - -This software is made available AS IS, and Xerox Corporation makes no warranty -about the software, its performance or its conformity to any specification. - -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| -|<--- this code is formatted to fit into 80 columns --->| - -*/ -package telecom; - -/** - * This simulation subclass implements AbstractSimulation.report(..) - * - */ -public class TimingSimulation extends AbstractSimulation { - - public static void main(String[] args){ - System.out.println("\n... Timing simulation 2 ...\n"); - simulation = new TimingSimulation(); - simulation.run(); - } - - /** - * Print a report of the connection time for customer - */ - protected void report(Customer c){ - Timing t = Timing.aspectOf(); - System.out.println(c + " spent " + t.getTotalConnectTime(c)); - } - -} diff --git a/docs/modules/ROOT/pages/examples/telecom/basic.lst b/docs/modules/ROOT/pages/examples/telecom/basic.lst deleted file mode 100644 index 018a679ac..000000000 --- a/docs/modules/ROOT/pages/examples/telecom/basic.lst +++ /dev/null @@ -1,7 +0,0 @@ -AbstractSimulation.java -BasicSimulation.java -Call.java -Connection.java -Local.java -LongDistance.java -Customer.java diff --git a/docs/modules/ROOT/pages/examples/telecom/billing.lst b/docs/modules/ROOT/pages/examples/telecom/billing.lst deleted file mode 100644 index 7b2cf087c..000000000 --- a/docs/modules/ROOT/pages/examples/telecom/billing.lst +++ /dev/null @@ -1,10 +0,0 @@ -AbstractSimulation.java -BillingSimulation.java -Call.java -Connection.java -Local.java -LongDistance.java -Customer.java -Timer.java -Billing.java -Timing.java diff --git a/docs/modules/ROOT/pages/examples/telecom/timing.lst b/docs/modules/ROOT/pages/examples/telecom/timing.lst deleted file mode 100644 index 3ca514f85..000000000 --- a/docs/modules/ROOT/pages/examples/telecom/timing.lst +++ /dev/null @@ -1,10 +0,0 @@ -AbstractSimulation.java -TimingSimulation.java -Call.java -Connection.java -Local.java -LongDistance.java -Customer.java -Timer.java -TimerLog.java -Timing.java |