Revision: 16440
Author: pavel.slegr
Date: Fri Jan 14 13:37:15 2011
Log: jbcp-5.x branch update - SS7
http://code.google.com/p/mobicents/source/detail?r=16440

Added:
 /branches/jbcp/5.x-mead/protocols/ss7/service
 /branches/jbcp/5.x-mead/protocols/ss7/service/pom.xml
 /branches/jbcp/5.x-mead/protocols/ss7/service/src
 /branches/jbcp/5.x-mead/protocols/ss7/service/src/main
 /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/assembly
 /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/assembly/common.xml
 /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/assembly/pojo.xml
 /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/config
/branches/jbcp/5.x-mead/protocols/ss7/service/src/main/config/jboss-beans.xml /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/config/jboss-structure.xml /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/config/sccp-routing.txt
 /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/java
 /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/java/org
 /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/java/org/mobicents
/branches/jbcp/5.x-mead/protocols/ss7/service/src/main/java/org/mobicents/ss7 /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/java/org/mobicents/ss7/SS7Service.java /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/java/org/mobicents/ss7/SS7ServiceMBean.java /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/java/org/mobicents/ss7/ShellExecutor.java
 /branches/jbcp/5.x-mead/protocols/ss7/ss7-assemble
 /branches/jbcp/5.x-mead/protocols/ss7/ss7-assemble/pom.xml
 /branches/jbcp/5.x-mead/protocols/ss7/ss7-assemble/src
 /branches/jbcp/5.x-mead/protocols/ss7/ss7-assemble/src/main
 /branches/jbcp/5.x-mead/protocols/ss7/ss7-assemble/src/main/assemble
/branches/jbcp/5.x-mead/protocols/ss7/ss7-assemble/src/main/assemble/descriptor.xml

=======================================
--- /dev/null
+++ /branches/jbcp/5.x-mead/protocols/ss7/service/pom.xml Fri Jan 14 13:37:15 2011
@@ -0,0 +1,172 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd";>
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <artifactId>ss7-parent</artifactId>
+               <groupId>org.mobicents.protocols.ss7</groupId>
+               <version>5.1.0.GA-JBCP5</version>
+       </parent>
+
+       <artifactId>mobicents-ss7</artifactId>
+
+       <name>Mobicents SS7</name>
+
+       <dependencies>
+               <dependency>
+                       <!-- This comes in container. -->
+                       <groupId>org.jboss.jbossas</groupId>
+                       <artifactId>jboss-as-system-jmx</artifactId>
+                       <version>${jboss.version}</version>
+                       <scope>compile</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.mobicents.protocols.ss7.sccp</groupId>
+                       <artifactId>sccp-api</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.mobicents.protocols.ss7.sccp</groupId>
+                       <artifactId>sccp-impl</artifactId>
+               </dependency>
+               <dependency>
+                       <artifactId>mtp</artifactId>
+                       <groupId>org.mobicents.protocols.ss7.mtp</groupId>
+               </dependency>
+               <dependency>
+                       <artifactId>linkset</artifactId>
+                       
<groupId>org.mobicents.protocols.ss7.management</groupId>
+               </dependency>
+
+               <!-- Hardware Dahdi Java-->
+               <dependency>
+                       <artifactId>mobicents-dahdi</artifactId>
+                       <groupId>org.mobicents.protocols.ss7.hardware</groupId>
+               </dependency>
+
+               <!-- Hardware Dialogic Java-->
+               <dependency>
+                       <artifactId>mobicents-dialogic</artifactId>
+                       <groupId>org.mobicents.protocols.ss7.hardware</groupId>
+               </dependency>
+
+               <!-- /hardware m3ua Java-->
+               <dependency>
+                       <artifactId>mobicents-m3ua</artifactId>
+                       <groupId>org.mobicents.protocols.ss7.hardware</groupId>
+               </dependency>
+
+               <dependency>
+                       <groupId>log4j</groupId>
+                       <artifactId>log4j</artifactId>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>concurrent</groupId>
+                       <artifactId>concurrent</artifactId>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>javolution</groupId>
+                       <artifactId>javolution</artifactId>
+               </dependency>
+               <dependency>
+                       <artifactId>shell</artifactId>
+                       
<groupId>org.mobicents.protocols.ss7.management</groupId>
+               </dependency>
+       </dependencies>
+       <build>
+               <finalName>${pom.artifactId}-${pom.version}</finalName>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-jar-plugin</artifactId>
+                               <configuration>
+                                       <archive>
+                                               
<addMavenDescriptor>false</addMavenDescriptor>
+                                       </archive>
+                               </configuration>
+                       </plugin>
+                       <plugin>
+                               <artifactId>maven-assembly-plugin</artifactId>
+                               <configuration>
+                                       <descriptors>
+                                               <descriptor>
+                                                       
src/main/assembly/pojo.xml
+                                               </descriptor>
+                                       </descriptors>
+                                       <!-- this is doubled in sccp-beans -->
+                                       <finalName>mobicents-ss7</finalName>
+                               </configuration>
+                               <executions>
+                                       <execution>
+                                               <phase>package</phase>
+                                               <goals>
+                                                       
<goal>directory-inline</goal>
+                                               </goals>
+                                       </execution>
+                               </executions>
+                       </plugin>
+
+
+                       <plugin>
+                               <artifactId>maven-antrun-plugin</artifactId>
+                               <executions>
+                                       <execution>
+                                               <id>deploy</id>
+                                               <phase>install</phase>
+                                               <goals>
+                                                       <goal>run</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <tasks>
+ <copy todir="${jboss.home}/server/${node}/deploy/mobicents-ss7-service">
+                                                                       <fileset 
dir="${project.build.directory}/mobicents-ss7-service">
+                                                                       
</fileset>
+                                                               </copy>
+                                                       </tasks>
+                                               </configuration>
+                                       </execution>
+                                       <execution>
+                                               <id>undeploy</id>
+                                               <phase>clean</phase>
+                                               <goals>
+                                                       <goal>run</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <tasks>
+                                                               <delete failonerror="false" 
includeemptydirs="true">
+ <fileset dir="${jboss.home}/server/${node}/deploy/mobicents-ss7-service" />
+                                                               </delete>
+                                                       </tasks>
+                                               </configuration>
+                                       </execution>
+                               </executions>
+                       </plugin>
+
+                       <plugin>
+                               <artifactId>maven-eclipse-plugin</artifactId>
+                               <groupId>org.mobicents.tools</groupId>
+                               <version>
+                                       
${mobicents.tools.mavenplugin.eclipse.version}
+                               </version>
+                               <inherited>false</inherited>
+                               <executions />
+                               <configuration>
+                                       <classpathExcludes>
+                                               
<exclude>xml-apis:xml-apis</exclude>
+                                               <exclude>jtidy:jtidy</exclude>
+                                       </classpathExcludes>
+                                       <resolveTransitiveDependencies>
+                                               true
+                                       </resolveTransitiveDependencies>
+                                       <eclipseProjectName>
+                                               mobicents-ss7-service
+                                       </eclipseProjectName>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </build>
+</project>
=======================================
--- /dev/null
+++ /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/assembly/common.xml Fri Jan 14 13:37:15 2011
@@ -0,0 +1,20 @@
+<component>
+       <dependencySets>
+               <dependencySet>
+                       <outputDirectory>/lib</outputDirectory>
+                       <unpack>false</unpack>
+                       <scope>runtime</scope>
+                       <excludes>
+                               
<exclude>org.jboss.jbossas:jboss-as-system-jmx</exclude>
+                       </excludes>
+               </dependencySet>
+               <dependencySet>
+                       <outputDirectory>/lib</outputDirectory>
+                       <unpack>false</unpack>
+                       <scope>compile</scope>
+                       <excludes>
+                               
<exclude>org.jboss.jbossas:jboss-as-system-jmx</exclude>
+                       </excludes>
+               </dependencySet>
+       </dependencySets>
+</component>
=======================================
--- /dev/null
+++ /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/assembly/pojo.xml Fri Jan 14 13:37:15 2011
@@ -0,0 +1,54 @@
+<assembly>
+       <id>service</id>
+       <formats>
+               <format>zip</format>
+       </formats>
+       <includeBaseDirectory>false</includeBaseDirectory>
+       <files>
+               <file>
+                       <source>src/main/config/jboss-beans.xml</source>
+                       <destName>META-INF/jboss-beans.xml</destName>
+                       <filtered>true</filtered>
+               </file>
+               <file>
+                       <source>src/main/config/jboss-structure.xml</source>
+                       <destName>META-INF/jboss-structure.xml</destName>
+               </file>
+               <file>
+                       <source>src/main/config/sccp-routing.txt</source>
+                       <destName>sccp-routing.txt</destName>
+               </file>
+       </files>
+       <dependencySets>
+               <dependencySet>
+                       <outputDirectory>/lib</outputDirectory>
+                       <unpack>false</unpack>
+                       <scope>compile</scope>
+                       <includes>
+                               
<include>org.mobicents.protocols.ss7.sccp:sccp-api</include>
+                               
<include>org.mobicents.protocols.ss7.sccp:sccp-impl</include>
+                               
<include>org.mobicents.protocols.ss7.m3ua:m3ua-api</include>
+                               
<include>org.mobicents.protocols.ss7.m3ua:m3ua-impl</include>
+                               
<include>org.mobicents.protocols.ss7.mtp:mtp</include>
+                               
<include>org.mobicents.protocols.stream:stream</include>
+                               
<include>org.mobicents.protocols.ss7:mobicents-ss7</include>
+                               <include>javolution:javolution</include>
+                               
<include>org.mobicents.protocols.ss7.management:shell</include>
+                               
<include>org.mobicents.protocols.ss7.management:linkset</include>
+
+                               
<include>org.mobicents.protocols.ss7.hardware:mobicents-dahdi</include>
+ <include>org.mobicents.protocols.ss7.hardware:mobicents-dialogic</include>
+                               
<include>org.mobicents.protocols.ss7.hardware:mobicents-m3ua</include>
+                       </includes>
+               </dependencySet>
+
+       </dependencySets>
+ <!-- DO NO USE componentDescriptors - seems like there is a bug which gets all deps, regardles of include/exclude -->
+       <!--
+       <componentDescriptors>
+               <componentDescriptor>
+                       src/main/assembly/common.xml
+               </componentDescriptor>
+       </componentDescriptors>
+        -->
+</assembly>
=======================================
--- /dev/null
+++ /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/config/jboss-beans.xml Fri Jan 14 13:37:15 2011
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns="urn:jboss:bean-deployer:2.0">
+
+       <bean name="LinksetFactoryFactory"
+               class="org.mobicents.ss7.linkset.oam.LinksetFactoryFactory">
+               <incallback method="addFactory" />
+               <uncallback method="removeFactory" />
+       </bean>
+
+       <bean name="DahdiLinksetFactory"
+               
class="org.mobicents.ss7.hardware.dahdi.oam.DahdiLinksetFactory">
+       </bean>
+
+       <bean name="DialogicLinksetFactory"
+               
class="org.mobicents.ss7.hardware.dialogic.oam.DialogicLinksetFactory">
+       </bean>
+
+       <bean name="M3UALinksetFactory"
+               class="org.mobicents.ss7.m3ua.oam.M3UALinksetFactory">
+       </bean>
+
+       <bean name="LinksetManager"
+               class="org.mobicents.ss7.linkset.oam.LinksetManager">
+
+               <property name="linksetFactoryFactory">
+                       <inject bean="LinksetFactoryFactory" />
+               </property>
+               <property name="persistDir">${jboss.server.data.dir}</property>
+       </bean>
+
+       <bean name="ShellExecutor"
+               class="org.mobicents.ss7.ShellExecutor">
+               <property name="address">${jboss.bind.address}</property>
+               <property name="port">3435</property>
+       </bean>
+
+       <!-- Mobicents SS7 service -->
+       <bean name="SS7Service" class="org.mobicents.ss7.SS7Service">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="org.mobicents.ss7:service=SS7Service",exposedInterface=org.mobicents.ss7.SS7ServiceMBean.class,registerDirectly=true)</annotation>
+               <property name="jndiName">java:/mobicents/ss7/sccp</property>
+ <property name="configPath">${catalina.home}/deploy/mobicents-ss7-service/sccp-routing.txt</property> + <property name="linksetManager"><inject bean="LinksetManager" /></property>
+               <property name="shellExecutor"><inject bean="ShellExecutor" 
/></property>
+       </bean>
+</deployment>
=======================================
--- /dev/null
+++ /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/config/jboss-structure.xml Fri Jan 14 13:37:15 2011
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<structure>
+    <context>
+        <path name=""/>
+        <metaDataPath>
+            <path name="META-INF"/>
+        </metaDataPath>
+        <classpath>
+            <path name="" />
+            <path name="lib" suffixes=".jar" />
+        </classpath>
+    </context>
+</structure>
=======================================
--- /dev/null
+++ /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/config/sccp-routing.txt Fri Jan 14 13:37:15 2011
@@ -0,0 +1,1 @@
+0; #ISDN_MOBILE#NATIONAL#9023629581# ; #ISDN_MOBILE#INTERNATIONAL#79023629581# ;linkset#14083#14155#0
=======================================
--- /dev/null
+++ /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/java/org/mobicents/ss7/SS7Service.java Fri Jan 14 13:37:15 2011
@@ -0,0 +1,154 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a full listing
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.mobicents.ss7;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import javolution.util.FastMap;
+
+import org.apache.log4j.Logger;
+import org.jboss.system.ServiceMBeanSupport;
+import org.mobicents.protocols.ss7.sccp.impl.SccpStackImpl;
+import org.mobicents.ss7.linkset.oam.Linkset;
+import org.mobicents.ss7.linkset.oam.LinksetExecutor;
+import org.mobicents.ss7.linkset.oam.LinksetManager;
+
+/**
+ * @author amit bhayani
+ * @author kulikov
+ */
+public class SS7Service extends ServiceMBeanSupport implements SS7ServiceMBean {
+
+    private ShellExecutor shellExecutor = null;
+
+    private LinksetManager linksetManager;
+    private SccpStackImpl sccpStack;
+
+    private String path;
+    private String jndiName;
+
+    private Logger logger = Logger.getLogger(SS7Service.class);
+
+    @Override
+    public void startService() throws Exception {
+        // starting sccp router
+        logger.info("Starting SCCP stack...");
+
+        sccpStack = new SccpStackImpl();
+        sccpStack.setConfigPath(path);
+
+        FastMap<String, Linkset> map = this.linksetManager.getLinksets();
+ for (FastMap.Entry<String, Linkset> e = map.head(), end = map.tail(); (e = e
+                .getNext()) != end;) {
+            Linkset value = e.getValue();
+            ((SccpStackImpl) sccpStack).add(value);
+        }
+
+        // sccpStack.setLinksets(linksets);
+        sccpStack.start();
+        rebind(sccpStack);
+
+        logger.info("SCCP stack Started. SccpProvider bound to "
+                + this.jndiName);
+
+        if (this.shellExecutor != null) {
+            LinksetExecutor linksetExec = new LinksetExecutor();
+            linksetExec.setLinksetManager(this.linksetManager);
+            this.shellExecutor.setLinksetExecutor(linksetExec);
+            this.shellExecutor.startService();
+        }
+
+        logger.info("[[[[[[[[[ Mobicents SS7 service started ]]]]]]]]]");
+    }
+
+    public void setJndiName(String jndiName) {
+        this.jndiName = jndiName;
+    }
+
+    public String getJndiName() {
+        return jndiName;
+    }
+
+    public void setConfigPath(String path) {
+        this.path = path;
+    }
+
+    public ShellExecutor getShellExecutor() {
+        return shellExecutor;
+    }
+
+    public void setShellExecutor(ShellExecutor shellExecutor) {
+        this.shellExecutor = shellExecutor;
+    }
+
+    @Override
+    public void stopService() {
+        try {
+            unbind(jndiName);
+        } catch (Exception e) {
+
+        }
+        if (this.shellExecutor != null) {
+            this.shellExecutor.stopService();
+        }
+
+        logger.info("Stopped SS7 service");
+    }
+
+    public void setLinksetManager(LinksetManager manager) {
+        this.linksetManager = manager;
+    }
+
+    public LinksetManager getLinksetManager() {
+        return linksetManager;
+    }
+
+    /**
+     * Binds trunk object to the JNDI under the jndiName.
+     */
+    private void rebind(SccpStackImpl stack) throws NamingException {
+        Context ctx = new InitialContext();
+        String tokens[] = jndiName.split("/");
+
+        for (int i = 0; i < tokens.length - 1; i++) {
+            if (tokens[i].trim().length() > 0) {
+                try {
+                    ctx = (Context) ctx.lookup(tokens[i]);
+                } catch (NamingException e) {
+                    ctx = ctx.createSubcontext(tokens[i]);
+                }
+            }
+        }
+
+        ctx.bind(tokens[tokens.length - 1], stack.getSccpProvider());
+    }
+
+    /**
+     * Unbounds object under specified name.
+     *
+     * @param jndiName
+     *            the JNDI name of the object to be unbound.
+     */
+    private void unbind(String jndiName) throws NamingException {
+        InitialContext initialContext = new InitialContext();
+        initialContext.unbind(jndiName);
+    }
+
+}
=======================================
--- /dev/null
+++ /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/java/org/mobicents/ss7/SS7ServiceMBean.java Fri Jan 14 13:37:15 2011
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a full listing
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+package org.mobicents.ss7;
+
+/**
+ *
+ * @author kulikov
+ */
+public interface SS7ServiceMBean {
+       public static final String ONAME = 
"org.mobicents.ss7:service=SS7Service";
+
+       public void start() throws Exception;
+       public void stop();
+     /**
+      * Returns SCCP Provider jndi name.
+      */
+        public String getJndiName();
+}
=======================================
--- /dev/null
+++ /branches/jbcp/5.x-mead/protocols/ss7/service/src/main/java/org/mobicents/ss7/ShellExecutor.java Fri Jan 14 13:37:15 2011
@@ -0,0 +1,236 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a full listing
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+package org.mobicents.ss7;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.channels.SelectionKey;
+
+import javolution.util.FastSet;
+
+import org.apache.log4j.Logger;
+import org.mobicents.ss7.linkset.oam.LinksetExecutor;
+import org.mobicents.ss7.management.console.Subject;
+import org.mobicents.ss7.management.transceiver.ChannelProvider;
+import org.mobicents.ss7.management.transceiver.ChannelSelectionKey;
+import org.mobicents.ss7.management.transceiver.ChannelSelector;
+import org.mobicents.ss7.management.transceiver.Message;
+import org.mobicents.ss7.management.transceiver.MessageFactory;
+import org.mobicents.ss7.management.transceiver.ShellChannel;
+import org.mobicents.ss7.management.transceiver.ShellServerChannel;
+
+/**
+ * @author amit bhayani
+ * @author kulikov
+ */
+public class ShellExecutor implements Runnable {
+
+    Logger logger = Logger.getLogger(ShellExecutor.class);
+
+    private ChannelProvider provider;
+    private ShellServerChannel serverChannel;
+    private ShellChannel channel;
+    private ChannelSelector selector;
+    private ChannelSelectionKey skey;
+
+    private MessageFactory messageFactory = null;
+
+    private String rxMessage = "";
+    private String txMessage = "";
+
+    private volatile boolean started = false;
+
+    private String address;
+
+    private int port;
+
+    private volatile LinksetExecutor linksetExecutor = null;
+
+    public ShellExecutor() throws IOException {
+
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    public int getPort() {
+        return port;
+    }
+
+    public void setPort(int port) {
+        this.port = port;
+    }
+
+    public void start() {
+
+    }
+
+    public void startService() throws IOException {
+
+        logger.info("Starting SS7 management shell environment");
+        provider = ChannelProvider.provider();
+        serverChannel = provider.openServerChannel();
+ InetSocketAddress inetSocketAddress = new InetSocketAddress(address,
+                port);
+        serverChannel.bind(inetSocketAddress);
+
+        selector = provider.openSelector();
+        skey = serverChannel.register(selector, SelectionKey.OP_ACCEPT);
+
+        messageFactory = ChannelProvider.provider().getMessageFactory();
+
+        this.logger.info(String.format("ShellExecutor listening at %s",
+                inetSocketAddress));
+
+        this.started = true;
+        new Thread(this).start();
+    }
+
+    public void stop() {
+    }
+
+    public void stopService() {
+        this.started = false;
+    }
+
+    public LinksetExecutor getLinksetExecutor() {
+        return linksetExecutor;
+    }
+
+    public void setLinksetExecutor(LinksetExecutor linksetExecutor) {
+        this.linksetExecutor = linksetExecutor;
+    }
+
+    public void run() {
+
+        while (started) {
+            try {
+                FastSet<ChannelSelectionKey> keys = selector.selectNow();
+
+ for (FastSet.Record record = keys.head(), end = keys.tail(); (record = record
+                        .getNext()) != end;) {
+                    ChannelSelectionKey key = (ChannelSelectionKey) keys
+                            .valueOf(record);
+
+                    if (key.isAcceptable()) {
+                        accept();
+                    } else if (key.isReadable()) {
+                        ShellChannel chan = (ShellChannel) key.channel();
+                        Message msg = (Message) chan.receive();
+
+                        if (msg != null) {
+                            rxMessage = msg.toString();
+                            System.out.println("received "+ rxMessage);
+                            if (rxMessage.compareTo("disconnect") == 0) {
+                                this.txMessage = "Bye";
+                                chan.send(messageFactory
+                                        .createMessage(txMessage));
+
+                            } else {
+                                String[] options = rxMessage.split(" ");
+                                Subject subject = Subject
+                                        .getSubject(options[0]);
+                                if (subject == null) {
+                                    chan.send(messageFactory
+ .createMessage("Invalid Subject"));
+                                } else {
+                                    // Nullify examined options
+                                    options[0] = null;
+
+                                    switch (subject) {
+                                    case LINKSET:
+ this.txMessage = this.linksetExecutor
+                                                .execute(options);
+                                        chan.send(messageFactory
+                                                
.createMessage(this.txMessage));
+                                        break;
+                                    }
+                                }
+                            } // if (rxMessage.compareTo("disconnect")
+                        } // if (msg != null)
+
+                        // TODO Handle message
+
+                        rxMessage = "";
+
+ } else if (key.isWritable() && txMessage.length() > 0) {
+
+                        if (this.txMessage.compareTo("Bye") == 0) {
+                            this.closeChannel();
+                        }
+
+                        // else {
+                        //
+ // ShellChannel chan = (ShellChannel) key.channel();
+                        // System.out.println("Sending " + txMessage);
+ // chan.send(messageFactory.createMessage(txMessage));
+                        // }
+
+                        this.txMessage = "";
+                    }
+                }
+            } catch (IOException e) {
+ logger.error("Error while operating on ChannelSelectionKey", e);
+            }
+
+            try {
+                Thread.sleep(100);
+            } catch (InterruptedException e) {
+            }
+        }
+
+        try {
+            skey.cancel();
+            if (channel != null) {
+                channel.close();
+            }
+            serverChannel.close();
+            selector.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        this.logger.info("Stopped ShellExecutor service");
+    }
+
+    private void accept() throws IOException {
+        channel = serverChannel.accept();
+        skey.cancel();
+        skey = channel.register(selector, SelectionKey.OP_READ
+                | SelectionKey.OP_WRITE);
+    }
+
+    private void closeChannel() throws IOException {
+        if (channel != null) {
+            try {
+                this.channel.close();
+            } catch (IOException e) {
+                logger.error("Error closing channel", e);
+            }
+        }
+        skey.cancel();
+        skey = serverChannel.register(selector, SelectionKey.OP_ACCEPT);
+    }
+
+}
=======================================
--- /dev/null
+++ /branches/jbcp/5.x-mead/protocols/ss7/ss7-assemble/pom.xml Fri Jan 14 13:37:15 2011
@@ -0,0 +1,162 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd";>
+       <modelVersion>4.0.0</modelVersion>
+
+       <parent>
+               <artifactId>ss7-parent</artifactId>
+               <groupId>org.mobicents.protocols.ss7</groupId>
+               <version>5.1.0.GA-JBCP5</version>
+       </parent>
+
+       <artifactId>ss7-assemble</artifactId>
+       <version>5.1.0.GA-JBCP5</version>
+       <packaging>pom</packaging>
+
+       <name>SS7 assembly</name>
+
+       <properties>
+               <isup.version>${pom.version}</isup.version>
+       </properties>
+
+
+       <dependencies>
+               <!-- ASN-->
+
+               <dependency>
+                       <groupId>org.mobicents.protocols.asn</groupId>
+                       <artifactId>asn</artifactId>
+                       <version>${pom.version}</version>
+               </dependency>
+
+               <!-- SS7 Service-->
+
+               <dependency>
+                       <groupId>org.mobicents.protocols.ss7.sccp</groupId>
+                       <artifactId>sccp-api</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.mobicents.protocols.ss7.sccp</groupId>
+                       <artifactId>sccp-impl</artifactId>
+                       <version>${pom.version}</version>
+               </dependency>
+               <dependency>
+                       <artifactId>mtp</artifactId>
+                       <groupId>org.mobicents.protocols.ss7.mtp</groupId>
+                       <version>${pom.version}</version>
+               </dependency>
+               <dependency>
+                       <artifactId>stream</artifactId>
+                       <groupId>org.mobicents.protocols.stream</groupId>
+                       <version>${pom.version}</version>
+               </dependency>
+               <dependency>
+                       <artifactId>linkset</artifactId>
+                       
<groupId>org.mobicents.protocols.ss7.management</groupId>
+               </dependency>
+               <dependency>
+                       <artifactId>m3ua-api</artifactId>
+                       <groupId>org.mobicents.protocols.ss7.m3ua</groupId>
+               </dependency>
+               <dependency>
+                       <artifactId>m3ua-impl</artifactId>
+                       <groupId>org.mobicents.protocols.ss7.m3ua</groupId>
+               </dependency>
+
+
+               <!-- Hardware Dahdi Java-->
+               <dependency>
+                       <artifactId>mobicents-dahdi</artifactId>
+                       <groupId>org.mobicents.protocols.ss7.hardware</groupId>
+               </dependency>
+
+               <!-- Hardware Dialogic Java-->
+               <dependency>
+                       <artifactId>mobicents-dialogic</artifactId>
+                       <groupId>org.mobicents.protocols.ss7.hardware</groupId>
+               </dependency>
+
+               <!-- /hardware m3ua Java-->
+               <dependency>
+                       <artifactId>mobicents-m3ua</artifactId>
+                       <groupId>org.mobicents.protocols.ss7.hardware</groupId>
+               </dependency>
+
+               <dependency>
+                       <groupId>javolution</groupId>
+                       <artifactId>javolution</artifactId>
+               </dependency>
+
+
+               <!-- Protocols-->
+
+
+               <dependency>
+                       <groupId>org.mobicents.protocols.ss7.map</groupId>
+                       <artifactId>map-api</artifactId>
+                       <version>${pom.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.mobicents.protocols.ss7.map</groupId>
+                       <artifactId>map-impl</artifactId>
+                       <version>${pom.version}</version>
+               </dependency>
+
+               <dependency>
+                       <groupId>org.mobicents.protocols.ss7.tcap</groupId>
+                       <artifactId>tcap-api</artifactId>
+                       <version>${pom.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.mobicents.protocols.ss7.tcap</groupId>
+                       <artifactId>tcap-impl</artifactId>
+                       <version>${pom.version}</version>
+               </dependency>
+
+               <dependency>
+                       <groupId>org.mobicents.protocols.ss7.isup</groupId>
+                       <artifactId>isup-api</artifactId>
+                       <version>${pom.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.mobicents.protocols.ss7.isup</groupId>
+                       <artifactId>isup-impl</artifactId>
+                       <version>${pom.version}</version>
+               </dependency>
+
+
+               <!-- Shell-->
+
+               <dependency>
+                       <artifactId>shell</artifactId>
+                       
<groupId>org.mobicents.protocols.ss7.management</groupId>
+                       <version>${pom.version}</version>
+               </dependency>
+
+
+       </dependencies>
+
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <artifactId>maven-assembly-plugin</artifactId>
+                               <configuration>
+                                       <descriptors>
+                                               <descriptor>
+                                                       
src/main/assemble/descriptor.xml
+                                               </descriptor>
+                                       </descriptors>
+                               </configuration>
+                               <executions>
+                                       <execution>
+                                               <id>make-assembly</id>
+                                               <phase>package</phase>
+                                               <goals>
+                                                       <goal>single</goal>
+                                                       
<goal>directory-single</goal>
+                                               </goals>
+                                       </execution>
+                               </executions>
+                       </plugin>
+               </plugins>
+       </build>
+</project>
=======================================
--- /dev/null
+++ /branches/jbcp/5.x-mead/protocols/ss7/ss7-assemble/src/main/assemble/descriptor.xml Fri Jan 14 13:37:15 2011
@@ -0,0 +1,91 @@
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0";
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd";>
+  <id>distribution</id>
+  <baseDirectory>/</baseDirectory>
+  <formats>
+    <format>zip</format>
+  </formats>
+       <files>
+               <file>
+                       
<source>${basedir}/../service/src/main/config/jboss-beans.xml</source>
+                       
<destName>ss7/mobicents-ss7-service/META-INF/jboss-beans.xml</destName>
+                       <filtered>true</filtered>
+               </file>
+               <file>
+ <source>${basedir}/../service/src/main/config/jboss-structure.xml</source> + <destName>ss7/mobicents-ss7-service/META-INF/jboss-structure.xml</destName>
+               </file>
+               <file>
+                       
<source>${basedir}/../service/src/main/config/sccp-routing.txt</source>
+                       
<destName>ss7/mobicents-ss7-service/sccp-routing.txt</destName>
+               </file>
+
+               <file>
+ <source>${basedir}/../management/shell/src/main/config/ss7-run.sh</source>
+                       <fileMode>0744</fileMode>
+                       <filtered>true</filtered>
+                       <destName>ss7/shell/bin/run.sh</destName>
+               </file>
+               <file>
+ <source>${basedir}/../management/shell/src/main/config/ss7-run.bat</source>
+                       <fileMode>0744</fileMode>
+                       <filtered>true</filtered>
+                       <destName>ss7/shell/bin/run.bat</destName>
+               </file>
+
+       </files>
+
+       <dependencySets>
+               <dependencySet>
+                       
<outputDirectory>/ss7/mobicents-ss7-service/lib</outputDirectory>
+                       <unpack>false</unpack>
+                       <scope>compile</scope>
+                       <includes>
+                               
<include>org.mobicents.protocols.ss7.sccp:sccp-api</include>
+                               
<include>org.mobicents.protocols.ss7.sccp:sccp-impl</include>
+                               
<include>org.mobicents.protocols.ss7.m3ua:m3ua-api</include>
+                               
<include>org.mobicents.protocols.ss7.m3ua:m3ua-impl</include>
+                               
<include>org.mobicents.protocols.ss7.mtp:mtp</include>
+                               
<include>org.mobicents.protocols.stream:stream</include>
+                               
<include>org.mobicents.protocols.ss7:mobicents-ss7</include>
+                               <include>javolution:javolution</include>
+                               
<include>org.mobicents.protocols.ss7.management:shell</include>
+                               
<include>org.mobicents.protocols.ss7.management:linkset</include>
+
+                               
<include>org.mobicents.protocols.ss7.hardware:mobicents-dahdi</include>
+ <include>org.mobicents.protocols.ss7.hardware:mobicents-dialogic</include>
+                               
<include>org.mobicents.protocols.ss7.hardware:mobicents-m3ua</include>
+                       </includes>
+               </dependencySet>
+               <dependencySet>
+             <outputDirectory>/ss7/protocols</outputDirectory>
+                 <scope>compile</scope>
+                 <useTransitiveDependencies>false</useTransitiveDependencies>
+                 <useProjectArtifact>false</useProjectArtifact>
+                 <includes>
+                       
<include>org.mobicents.protocols.ss7.map:map*:jar</include>
+                       
<include>org.mobicents.protocols.ss7.tcap:tcap*:jar</include>
+                       
<include>org.mobicents.protocols.ss7.isup:isup*:jar</include>
+                 </includes>
+               </dependencySet>
+               <dependencySet>
+             <outputDirectory>/ss7/shell</outputDirectory>
+                 <scope>compile</scope>
+                 <useTransitiveDependencies>false</useTransitiveDependencies>
+                 <useProjectArtifact>false</useProjectArtifact>
+                 <includes>
+                       
<include>org.mobicents.protocols.ss7.management:shell</include>
+                 </includes>
+               </dependencySet>
+               <dependencySet>
+             <outputDirectory>/asn</outputDirectory>
+                 <scope>compile</scope>
+                 <useTransitiveDependencies>false</useTransitiveDependencies>
+                 <useProjectArtifact>false</useProjectArtifact>
+                 <includes>
+                       <include>org.mobicents.protocols.asn:asn</include>
+                 </includes>
+               </dependencySet>
+       </dependencySets>
+</assembly>

Reply via email to