001
002 import java.io.IOException;
003
004 /**
005 * Application receives account transactions and performs the transactions.
006 * @author Heinz Kredel.
007 */
008 public class NetzBuchungBuche {
009
010 private static int anzahl = 0;
011 private static ChannelFactory cf = null;
012 private static SocketChannel channel = null;
013 private final static String finis = "finis";
014
015 private static KontoS [] konten;
016 private static int kmax;
017 private static int umax = 300;
018
019
020 public static void main(String[] args) throws InterruptedException {
021
022 final int kmax = 30;
023 KontoS[] konten = new KontoS[kmax];
024 double balance = 0.0;
025 double stand;
026
027 for (int i = 0; i < kmax; i++) {
028 konten[i] = new KontoS( 5000 );
029 stand = konten[i].zeigeGeld();
030 balance += stand;
031 System.out.println("Kontostand i = " + i
032 + " Betrag = " + konten[i].zeigeGeld() );
033 }
034 System.out.println("Balance " + balance);
035
036 cf = new ChannelFactory(30000);
037
038
039 while (true) {
040
041 try {
042 channel = cf.getChannel();
043 } catch (IOException e) {
044 e.printStackTrace();
045 return;
046 }
047
048
049 System.out.println("Starting ... ");
050 Object o = null;
051 for ( ; ; ) {
052 anzahl++;
053 // System.out.println("channel.recieve = " + anzahl );
054
055 try { o = channel.receive(); }
056 catch (IOException e) {
057 System.err.println(e); return; }
058 catch (ClassNotFoundException e) {
059 System.err.println(e); return; }
060
061 if ( o instanceof String ) {
062 String os = (String) o;
063 if ( os.equals(finis) ) break;
064 }
065 UeberweisungS u = (UeberweisungS) o;
066 u.run(konten);
067 }
068 System.out.println("... finished " + anzahl + " records.");
069
070 balance = 0.0;
071 for (int i = 0; i < kmax; i++) {
072 stand = konten[i].zeigeGeld();
073 balance += stand;
074 System.out.println("Kontostand i = " + i
075 + " Betrag = " + konten[i].zeigeGeld() );
076 }
077 System.out.println("Balance " + balance);
078
079 }
080 }
081
082 }