Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/tools/ExternalEvaluation/Java/ExternalEvaluation.Service/src/com/heuristiclab/problems/externalevaluation/StreamListener.java @ 15014

Last change on this file since 15014 was 15014, checked in by pfleck, 7 years ago

Added code and tools for the ExternalEvaluationProblem. (e.g. Java-side evaluation)

File size: 1.2 KB
Line 
1package com.heuristiclab.problems.externalevaluation;
2
3import java.io.*;
4import java.util.*;
5
6public class StreamListener implements IListener {
7  private InputStream input;
8  private OutputStream output;
9  private ArrayList<ChannelDiscoveredEventListener> listenerList;
10 
11  public StreamListener(InputStream input, OutputStream output) {
12    this.input = input;
13    this.output = output;
14    this.listenerList = new ArrayList<ChannelDiscoveredEventListener>();
15  }
16 
17  @Override
18  public void listen() {
19    onDiscovered(new StreamChannel(this.input, this.output));
20  }
21
22  @Override
23  public void stop() {
24  }
25
26  @Override
27  public void addChannelDiscoveredEventListener(
28      ChannelDiscoveredEventListener l) {
29    synchronized (listenerList) {
30      listenerList.add(l);
31    }
32  }
33
34  @Override
35  public void removeChannelDiscoveredEventListener(
36      ChannelDiscoveredEventListener l) {
37    synchronized (listenerList) {
38      listenerList.remove(l);
39    }
40  }
41 
42  private void onDiscovered(IChannel channel) {
43    synchronized(listenerList) {
44      Iterator<ChannelDiscoveredEventListener> listeners = listenerList.iterator();
45      while( listeners.hasNext() ) {
46        listeners.next().discovered(new EventObject(channel));
47      }
48    }
49  }
50
51}
Note: See TracBrowser for help on using the repository browser.