View Javadoc

1   /*
2    * Copyright (c) 2014. Peter Crossley (xley.com)
3    *  Licensed to the Apache Software Foundation (ASF) under one
4    *  or more contributor license agreements.  See the NOTICE file
5    *  distributed with this work for additional information
6    *  regarding copyright ownership.  The ASF licenses this file
7    *  to you under the Apache License, Version 2.0 (the
8    *  "License"); you may not use this file except in compliance
9    *  with the License.  You may obtain a copy of the License at
10   *
11   *    http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *  Unless required by applicable law or agreed to in writing,
14   *  software distributed under the License is distributed on an
15   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   *  KIND, either express or implied.  See the License for the
17   *  specific language governing permissions and limitations
18   *  under the License.
19   */
20  
21  package com.xley.lfosc.impl;
22  
23  import com.illposed.osc.OSCMessage;
24  import com.xley.lfosc.util.LogUtil;
25  
26  import java.util.Date;
27  import java.util.concurrent.ExecutorService;
28  import java.util.concurrent.Executors;
29  import java.util.concurrent.TimeUnit;
30  
31  /**
32   * The type OSC bridge listener.
33   */
34  public class OSCProxyListener implements com.illposed.osc.OSCListener {
35  
36      /**
37       * Executor for LightFactory outbound connections.
38       */
39      private final ExecutorService executorService = Executors.newFixedThreadPool(5);
40  
41  
42      @Override
43      public final void acceptMessage(final Date time, final OSCMessage message) {
44          executorService.submit(new OSCProtocol(message));
45      }
46  
47      public void shutdown() {
48          executorService.shutdown();
49          try {
50              executorService.awaitTermination(5000, TimeUnit.MILLISECONDS);
51          } catch (InterruptedException e) {
52              LogUtil.trace(getClass(), e);
53          }
54      }
55  
56  }