eriezelagera

Java - Sample using SMS Framework

Sep 2nd, 2014
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.14 KB | None | 0 0
  1. public class SampleClass extends SMSModule {
  2.  
  3.     // Recieve service
  4.     private final ScheduledExecutorService recieve_d = Executors.newScheduledThreadPool(1);
  5.     // Send service
  6.     private final ScheduledExecutorService send_d = Executors.newScheduledThreadPool(1);
  7.  
  8.     public SampleClass() {
  9.         initServices();
  10.        
  11.         // Manually send or read
  12.         // Throws exceptions
  13.         super.send("093512345678", "Test");
  14.         int i = 0;
  15.         for (String msg : super.read(InboundMessage.MessageClasses.ALL)) {
  16.             System.out.println("Message #" + i++ + ": " + msg);
  17.         }
  18.         i = 0;
  19.         for (InboudMessage msg : super.readIM(InboundMessage.MessageClasses.ALL)) {
  20.             System.out.println("From: " + msg.getOriginator());
  21.             System.out.println("Date: " + msg.getDate());
  22.             System.out.println("Message #" + i++ + ": " + msg);
  23.         }
  24.         super.readOut(InboundMessage.MessageClasses.ALL);
  25.     }
  26.  
  27.     private void initServices() {
  28.         recieve_d.scheduleWithFixedDelay(recieveService, 0, 5, TimeUnit.SECONDS);
  29.         send_d.scheduleWithFixedDelay(sendService, 0, 5, TimeUnit.SECONDS);
  30.     }
  31.  
  32.     public static void main(String[] args) {
  33.         SwingUtilities.invokeLater(new Runnable() {
  34.             public void run() {
  35.                 if (start()) {
  36.                             System.out.println("SMS Gateway successfully started!");
  37.                     new SampleClass();
  38.                         }
  39.             }
  40.         )};
  41.     }
  42.    
  43.     /** Nested class (can be created with to class) which implements Runnable. **/
  44.     private final Runnable recieveService = new Runnable() {
  45.             @Override
  46.             public void run() {
  47.             // Throws exceptions, surround with try-catch
  48.                     super.readOut(InboundMessage.MessageClasses.ALL);
  49.             }
  50.         };
  51.     private final Runnable sendService = new Runnable() {
  52.             @Override
  53.             public void run() {
  54.                     // Create action here
  55.             /* Psuedo code - processing SMS messages */
  56.             /*
  57.             Check for new messages - read(class) or readIM(class)
  58.             // Throws exceptions, surround with try-catch
  59.             for (InboundMessage msg : read(class)) {
  60.                 if (msg.getText().equalsIgnoreCase("BAL")) {
  61.                     super.send(msg.getOriginator(), "Your current balance is ...");
  62.                 }
  63.                 // Other commands
  64.             }
  65.             */
  66.             }
  67.         };
  68.    
  69. }
Advertisement
Add Comment
Please, Sign In to add comment