Revision: b3aec7534183
Author:   Oifa Yulian <[email protected]>
Date:     Mon Jun 18 08:24:16 2012
Log:      Updated Shell Executor

http://code.google.com/p/jss7/source/detail?r=b3aec7534183

Deleted:
 /sgw/gateway/src/main/java/org/mobicents/ss7/sgw/ShellExecutor.java
Modified:
 /service/src/main/config/jboss-beans.xml
 /service/src/main/java/org/mobicents/ss7/ShellExecutor.java
 /sgw/boot/src/main/config/sgw-beans.xml
 /sgw/gateway/pom.xml
 /sgw/gateway/src/main/java/org/mobicents/ss7/sgw/SignalingGateway.java

=======================================
--- /sgw/gateway/src/main/java/org/mobicents/ss7/sgw/ShellExecutor.java Thu May 17 05:52:04 2012
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.mobicents.ss7.sgw;
-
-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.protocols.ss7.m3ua.impl.oam.M3UAShellExecutor;
-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;
-
-import org.mobicents.protocols.ss7.scheduler.Scheduler;
-import org.mobicents.protocols.ss7.scheduler.Task;
-
-/**
- *
- * @author amit bhayani
- *
- */
-public class ShellExecutor extends Task {
-
-    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 LinksetExecutor linksetExecutor = null;
-
-    private M3UAShellExecutor m3UAShellExecutor = null;
-
-    private volatile boolean started = false;
-
-    private String address;
-
-    private int port;
-
-    public ShellExecutor(Scheduler scheduler) throws IOException {
-       super(scheduler);
-    }
-
-    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 LinksetExecutor getLinksetExecutor() {
-        return linksetExecutor;
-    }
-
-    public void setLinksetExecutor(LinksetExecutor linksetExecutor) {
-        this.linksetExecutor = linksetExecutor;
-    }
-
-    public M3UAShellExecutor getM3UAShellExecutor() {
-        return m3UAShellExecutor;
-    }
-
-    public void setM3UAShellExecutor(M3UAShellExecutor shellExecutor) {
-        m3UAShellExecutor = shellExecutor;
-    }
-
-    public int getQueueNumber()
-       {
-               return scheduler.MANAGEMENT_QUEUE;
-       }
-
-    public void start() throws IOException {
-       try
-       {
-        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;
-        this.activate(false);
-               scheduler.submit(this,scheduler.MANAGEMENT_QUEUE);
-       }
-       catch(Exception e)
-       {
-               logger.error("Exception occured",e);
-       }
-    }
-
-    public void stop() {
-        this.started = false;
-
-        try {
-            skey.cancel();
-            if (channel != null) {
-                channel.close();
-            }
-            serverChannel.close();
-            selector.close();
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
-
-    @Override
-    public long perform() {
-       if (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) {
-                            System.out.println("Receive " + msg);
-                            rxMessage = msg.toString();
-
-                            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;
-                                    case M3UA:
- this.txMessage = this.m3UAShellExecutor.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();
-                        }
-                        this.txMessage = "";
-                    }
-                }
-            } catch (IOException e) {
- logger.error("Error while operating on ChannelSelectionKey", e);
-            }
-
-               scheduler.submit(this,scheduler.MANAGEMENT_QUEUE);
-        }
-
-       return 0;
-    }
-
-    private void accept() throws IOException {
-        channel = serverChannel.accept();
-        skey.cancel();
- skey = channel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);
-        System.out.println("Client connected");
-    }
-
-    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);
-    }
-}
=======================================
--- /service/src/main/config/jboss-beans.xml    Sun Jun 17 08:45:31 2012
+++ /service/src/main/config/jboss-beans.xml    Mon Jun 18 08:24:16 2012
@@ -91,6 +91,12 @@
<!-- ==================================================================== -->
        <!-- Define Shell Executor -->
        <bean name="ShellExecutor" class="org.mobicents.ss7.ShellExecutor">
+               <constructor>
+                       <parameter>
+                               <inject bean="SS7Scheduler" />
+                       </parameter>
+               </constructor>
+
                <property name="address">${jboss.bind.address}</property>
                <property name="port">3435</property>

=======================================
--- /service/src/main/java/org/mobicents/ss7/ShellExecutor.java Mon Apr 23 10:53:14 2012 +++ /service/src/main/java/org/mobicents/ss7/ShellExecutor.java Mon Jun 18 08:24:16 2012
@@ -29,6 +29,8 @@
 import javolution.util.FastSet;

 import org.apache.log4j.Logger;
+import org.mobicents.protocols.ss7.scheduler.Scheduler;
+import org.mobicents.protocols.ss7.scheduler.Task;
 import org.mobicents.protocols.ss7.m3ua.impl.oam.M3UAShellExecutor;
 import org.mobicents.protocols.ss7.sccp.impl.oam.SccpExecutor;
 import org.mobicents.ss7.linkset.oam.LinksetExecutor;
@@ -45,7 +47,7 @@
  * @author amit bhayani
  * @author kulikov
  */
-public class ShellExecutor implements Runnable {
+public class ShellExecutor extends Task {

        Logger logger = Logger.getLogger(ShellExecutor.class);

@@ -72,8 +74,8 @@

        private volatile SccpExecutor sccpExecutor = null;

-       public ShellExecutor() throws IOException {
-
+       public ShellExecutor(Scheduler scheduler) throws IOException {
+               super(scheduler);
        }

        public SccpExecutor getSccpExecutor() {
@@ -115,11 +117,25 @@
this.logger.info(String.format("ShellExecutor listening at %s", inetSocketAddress));

                this.started = true;
-               new Thread(this).start();
+        this.activate(false);
+               scheduler.submit(this,scheduler.MANAGEMENT_QUEUE);
        }

        public void stop() {
                this.started = false;
+
+               try {
+            skey.cancel();
+            if (channel != null) {
+                channel.close();
+            }
+            serverChannel.close();
+            selector.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+               this.logger.info("Stopped ShellExecutor service");
        }

        public LinksetExecutor getLinksetExecutor() {
@@ -138,123 +154,113 @@
                m3UAShellExecutor = shellExecutor;
        }

-       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));
-
+       public int getQueueNumber()
+       {
+               return scheduler.MANAGEMENT_QUEUE;
+       }
+
+       public long perform() {
+
+               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 {
-                                                               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:
-                                                                               
if(this.linksetExecutor == null){
-                                                                                       
this.txMessage = "Error! LinksetExecutor is null";
-                                                                               
} else{
-                                                                               
        this.txMessage = this.linksetExecutor.execute(options);
-                                                                               
}
-                                                                               
break;
-                                                                       case 
SCTP:
-                                                                       case 
M3UA:
-                                                                               
if(this.m3UAShellExecutor == null){
-                                                                                       
this.txMessage = "Error! M3UAShellExecutor is null";
-                                                                               
} else {
-                                                                               
        this.txMessage = this.m3UAShellExecutor.execute(options);
-                                                                               
}
-                                                                               
break;
-                                                                       case 
SCCP:
-                                                                               
if(this.sccpExecutor == null){
-                                                                                       
this.txMessage = "Error! SccpExecutor is null";
-                                                                               
} else {
-                                                                               
        this.txMessage = this.sccpExecutor.execute(options);
-                                                                               
}
-                                                                               
break;
-                                                                       default:
-                                                                               
this.txMessage = "Invalid Subject";
-                                                                               
break;
-                                                                       }
-                                                                       
chan.send(messageFactory.createMessage(this.txMessage));
-                                                               }
-                                                       } // 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("IO Exception while operating on ChannelSelectionKey. Client CLI connection will be closed now", e);
-                               try {
-                                       this.closeChannel();
-                               } catch (IOException e1) {
-                                       logger.error("IO Exception while closing 
Channel", e);
-                               }
-                       } catch (Exception e){
- logger.error("Exception while operating on ChannelSelectionKey. Client CLI connection will be closed now", e);
-                               try {
-                                       this.closeChannel();
-                               } catch (IOException e1) {
-                                       logger.error("IO Exception while closing 
Channel", e);
+                                                               // Nullify 
examined options
+                                                               //options[0] = 
null;
+
+                                                               switch 
(subject) {
+                                                               case LINKSET:
+                                                                       
if(this.linksetExecutor == null){
+                                                                               
this.txMessage = "Error! LinksetExecutor is null";
+                                                                       } else{
+                                                                               
this.txMessage = this.linksetExecutor.execute(options);
+                                                                       }
+                                                                       break;
+                                                               case SCTP:
+                                                               case M3UA:
+                                                                       
if(this.m3UAShellExecutor == null){
+                                                                               
this.txMessage = "Error! M3UAShellExecutor is null";
+                                                                       } else {
+                                                                               
this.txMessage = this.m3UAShellExecutor.execute(options);
+                                                                       }
+                                                                       break;
+                                                               case SCCP:
+                                                                       
if(this.sccpExecutor == null){
+                                                                               
this.txMessage = "Error! SccpExecutor is null";
+                                                                       } else {
+                                                                               
this.txMessage = this.sccpExecutor.execute(options);
+                                                                       }
+                                                                       break;
+                                                               default:
+                                                                       this.txMessage = 
"Invalid Subject";
+                                                                       break;
+                                                               }
+                                                               
chan.send(messageFactory.createMessage(this.txMessage));
+                                                       }
+                                               } // 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("IO Exception while operating on ChannelSelectionKey. Client CLI connection will be closed now", 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");
+                               this.closeChannel();
+                       } catch (IOException e1) {
+                               logger.error("IO Exception while closing 
Channel", e);
+                       }
+               } catch (Exception e){
+ logger.error("Exception while operating on ChannelSelectionKey. Client CLI connection will be closed now", e);
+                       try {
+                               this.closeChannel();
+                       } catch (IOException e1) {
+                               logger.error("IO Exception while closing 
Channel", e);
+                       }
+               }
+
+               if(this.started)
+                       scheduler.submit(this,scheduler.MANAGEMENT_QUEUE);
+
+               return 0;
        }

        private void accept() throws IOException {
=======================================
--- /sgw/boot/src/main/config/sgw-beans.xml     Thu May 17 05:52:04 2012
+++ /sgw/boot/src/main/config/sgw-beans.xml     Mon Jun 18 08:24:16 2012
@@ -74,7 +74,7 @@
                <uncallback method="removeFactory" />
        </bean>

-       <bean name="ShellExecutor" class="org.mobicents.ss7.sgw.ShellExecutor">
+       <bean name="ShellExecutor" class="org.mobicents.ss7.ShellExecutor">
                <constructor>
                        <parameter>
                                <inject bean="Scheduler" />
=======================================
--- /sgw/gateway/pom.xml        Sun Jun 17 10:45:11 2012
+++ /sgw/gateway/pom.xml        Mon Jun 18 08:24:16 2012
@@ -51,7 +51,7 @@
                        <artifactId>m3ua-impl</artifactId>
                        <groupId>org.mobicents.protocols.ss7.m3ua</groupId>
                </dependency>
-
+
                <!-- Hardware Dahdi Java -->
                <dependency>
                        <artifactId>mobicents-dahdi</artifactId>
@@ -64,6 +64,13 @@
                        <groupId>org.mobicents.protocols.ss7.hardware</groupId>
                </dependency>

+               <!-- Service used for Shell Executor -->
+               <dependency>
+                       <artifactId>mobicents-ss7</artifactId>
+                       <groupId>org.mobicents.protocols.ss7</groupId>
+                       <version>${pom.version}</version>
+               </dependency>
+
                <dependency>
                        <groupId>log4j</groupId>
                        <artifactId>log4j</artifactId>
=======================================
--- /sgw/gateway/src/main/java/org/mobicents/ss7/sgw/SignalingGateway.java Thu May 17 05:52:04 2012 +++ /sgw/gateway/src/main/java/org/mobicents/ss7/sgw/SignalingGateway.java Mon Jun 18 08:24:16 2012
@@ -25,6 +25,7 @@
 import java.io.IOException;

 import org.apache.log4j.Logger;
+import org.mobicents.ss7.ShellExecutor;
 import org.mobicents.protocols.ss7.scheduler.Scheduler;
 import org.mobicents.protocols.ss7.scheduler.Task;

Reply via email to