001    
002    import java.io.IOException;
003    
004    /**
005     * Application generates various transactions for accounting
006     * and passes them through a generated socket for processing.
007     * @author Heinz Kredel.
008     */
009    
010    public class NetzBuchungGenerate {
011    
012        private static int anzahl = 100;
013        private static ChannelFactory cf = null;
014        private static SocketChannel channel = null;
015        private final static String finis = "finis";
016    
017        private static int kmax;
018        private static int umax = 300;
019    
020        private static String hostname = "localhost";
021        private static int port = 30000;
022    
023    
024        public static void main(String[] args) throws InterruptedException {
025    
026            final int kmax = 30;
027            final int bmax = 1000;
028    
029            if ( args.length > 0 ) hostname = args[0];
030    
031            cf = new ChannelFactory(port+1); 
032    
033            try { channel = cf.getChannel(hostname,port);
034            } catch (IOException e) { System.err.println(e); return; }
035    
036    
037            System.out.println("Starting ... ");
038            for ( int i = 0; i < anzahl; i++ ) {
039    
040                int g = (int) (umax * Math.random());
041                int a = (int) (kmax * Math.random());
042                int b = (int) (kmax * Math.random());
043    
044                System.out.println("Ueberweisung " + i + ":" +
045                           " Konto a = " + a +
046                           " Konto b = " + b +
047                                   " Betrag g = " + g );
048    
049                Object u = (Object) new UeberweisungS(a,b,g); 
050    
051                try { channel.send( u ); }
052                catch (IOException e) {
053                      System.err.println(e); return; }
054    
055            }
056    
057            try { channel.send( (Object) finis ); }
058            catch (IOException e) {
059                  System.err.println(e); return; }
060            System.out.println("... finished " + anzahl + " records.");
061            System.exit(1);
062    
063        }
064    
065    }