001/* 002 * This file is part of the Kompics component model runtime. 003 * 004 * Copyright (C) 2009 Swedish Institute of Computer Science (SICS) Copyright (C) 005 * 2009 Royal Institute of Technology (KTH) 006 * 007 * Kompics is free software; you can redistribute it and/or modify it under the 008 * terms of the GNU General Public License as published by the Free Software 009 * Foundation; either version 2 of the License, or (at your option) any later 010 * version. 011 * 012 * This program is distributed in the hope that it will be useful, but WITHOUT 013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 014 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 015 * details. 016 * 017 * You should have received a copy of the GNU General Public License along with 018 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 019 * Place - Suite 330, Boston, MA 02111-1307, USA. 020 */ 021package se.sics.kompics; 022 023/** 024 * 025 * @author Lars Kroll {@literal <[email protected]>} 026 */ 027public abstract class SimpleChannel<PT extends PortType> implements ChannelCore<PT> { 028 /* === PRIVATE === */ 029 protected volatile boolean destroyed = false; 030 protected final PortCore<PT> positivePort; 031 protected final PortCore<PT> negativePort; 032 protected final PT portType; 033 034 public SimpleChannel(PortCore<PT> positivePort, PortCore<PT> negativePort) { 035 this.positivePort = positivePort; 036 this.negativePort = negativePort; 037 this.portType = positivePort.portType; 038 } 039 040 @Override 041 public boolean isDestroyed() { 042 return destroyed; 043 } 044 045 private void destroy() { 046 destroyed = true; 047 } 048 049 @Override 050 public boolean hasPositivePort(Port<PT> port) { 051 return positivePort == port; 052 } 053 054 @Override 055 public boolean hasNegativePort(Port<PT> port) { 056 return negativePort == port; 057 } 058 059 @Override 060 public void disconnect() { 061 this.destroy(); 062 positivePort.removeChannel(this); 063 negativePort.removeChannel(this); 064 } 065 066 @Override 067 public PT getPortType() { 068 return portType; 069 } 070}