001package com.pi4j.io.gpio.impl;
002
003/*
004 * #%L
005 * **********************************************************************
006 * ORGANIZATION  :  Pi4J
007 * PROJECT       :  Pi4J :: Java Library (Core)
008 * FILENAME      :  GpioEventMonitorExecutorImpl.java  
009 * 
010 * This file is part of the Pi4J project. More information about 
011 * this project can be found here:  http://www.pi4j.com/
012 * **********************************************************************
013 * %%
014 * Copyright (C) 2012 - 2013 Pi4J
015 * %%
016 * Licensed under the Apache License, Version 2.0 (the "License"); you
017 * may not use this file except in compliance with the License. You may obtain a copy of the License
018 * at
019 * 
020 * http://www.apache.org/licenses/LICENSE-2.0
021 * 
022 * Unless required by applicable law or agreed to in writing, software distributed under the License
023 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
024 * or implied. See the License for the specific language governing permissions and limitations under
025 * the License.
026 * #L%
027 */
028
029import java.util.concurrent.ExecutorService;
030import com.pi4j.io.gpio.GpioFactory;
031import com.pi4j.io.gpio.GpioPinInput;
032import com.pi4j.io.gpio.event.PinEvent;
033import com.pi4j.io.gpio.event.PinListener;
034import com.pi4j.io.gpio.tasks.impl.GpioEventDispatchTaskImpl;
035
036public class GpioEventMonitorExecutorImpl implements PinListener {
037    
038    private final GpioPinInput pin;
039    private static ExecutorService executor;
040    
041    public GpioEventMonitorExecutorImpl(GpioPinInput pin) {
042        this.pin = pin;        
043        executor = GpioFactory.getExecutorServiceFactory().newSingleThreadExecutorService();
044    }
045    
046    @Override
047    public void handlePinEvent(PinEvent event) {
048        executor.execute(new GpioEventDispatchTaskImpl(pin, event));
049    }
050}