Free cookie consent management tool by TermsFeed Policy Generator

Changes between Version 7 and Version 8 of Documentation/Howto/OptimizeExternalApplications


Ignore:
Timestamp:
06/04/10 16:24:34 (14 years ago)
Author:
abeham
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/Howto/OptimizeExternalApplications

    v7 v8  
    5353[[Image(ExternalEvaluationServiceTestCD.png)]]
    5454
    55 Here is the java code for the main method of the `RandomStreamingPollEvaluator`
     55
     56==== Usage examples ====
     57
     58Here is the java code for the `RandomStreamingPollEvaluator`
    5659
    5760{{{#!java
    58 public static void main(String[] args) {
    59         StreamChannelFactory factory = new StreamChannelFactory(System.in, System.out);
    60         PollService service = new PollService(factory, 1);
    61         service.start();
    62        
    63         Random random = new Random();
    64         while (true) {
    65                 SolutionMessage msg = service.getSolution();
    66                 // parse the message and retrieve the variables there
    67                 try {
    68                         service.sendQuality(msg, random.nextDouble());
    69                 } catch (IOException e) {
    70                         break;
     61public class RandomStreamingPollEvaluator {
     62
     63        public static void main(String[] args) {
     64                StreamChannelFactory factory = new StreamChannelFactory(System.in, System.out);
     65                PollService service = new PollService(factory, 1);
     66                service.start();
     67               
     68                Random random = new Random();
     69                while (true) {
     70                        SolutionMessage msg = service.getSolution();
     71                        // parse the message and retrieve the variables there
     72                        try {
     73                                service.sendQuality(msg, random.nextDouble());
     74                        } catch (IOException e) {
     75                                break;
     76                        }
    7177                }
     78               
     79                service.stop();
    7280        }
    73        
    74         service.stop();
    7581}
    7682}}}
    7783
    78 This code shows a concrete example of how to use the !PollService and the ease of integrating this into an external java application.
     84This code shows a concrete example of how to use the !PollService and the ease of integrating this into an external java application. Using a !PushService is slightly different as can be seen in the following example. As mentioned it depends on the application which of the two possibilities is more suited.
     85
     86{{{#!java
     87public class RandomSocketPushEvaluator {
     88        private PushService service;
     89       
     90        public static void main(String[] args) {
     91                RandomSocketPushEvaluator main = new RandomSocketPushEvaluator();
     92                main.run();
     93                System.out.println("Service is running, terminate by pressing <Return> or <Enter>.");
     94                System.console().readLine();
     95                main.terminate();
     96        }
     97       
     98        private void run() {
     99                ServerSocketChannelFactory factory = new ServerSocketChannelFactory(8843);
     100                service = new PushService(factory, 1, new RandomEvaluator());
     101                service.start();
     102        }
     103       
     104        private void terminate() {
     105                service.stop();
     106        }
     107       
     108        private class RandomEvaluator implements IEvaluationService {
     109                Random random;
     110               
     111                public RandomEvaluator() {
     112                        random = new Random();
     113                }
     114               
     115                @Override
     116                public double evaluate(SolutionMessage msg) {
     117                        return random.nextDouble();
     118                }
     119               
     120        }
     121}
     122}}}
    79123
    80124=== Preparing an `ExternalEvaluationProblem` ===