Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SampleClass extends SMSModule {
- // Recieve service
- private final ScheduledExecutorService recieve_d = Executors.newScheduledThreadPool(1);
- // Send service
- private final ScheduledExecutorService send_d = Executors.newScheduledThreadPool(1);
- public SampleClass() {
- initServices();
- // Manually send or read
- // Throws exceptions
- super.send("093512345678", "Test");
- int i = 0;
- for (String msg : super.read(InboundMessage.MessageClasses.ALL)) {
- System.out.println("Message #" + i++ + ": " + msg);
- }
- i = 0;
- for (InboudMessage msg : super.readIM(InboundMessage.MessageClasses.ALL)) {
- System.out.println("From: " + msg.getOriginator());
- System.out.println("Date: " + msg.getDate());
- System.out.println("Message #" + i++ + ": " + msg);
- }
- super.readOut(InboundMessage.MessageClasses.ALL);
- }
- private void initServices() {
- recieve_d.scheduleWithFixedDelay(recieveService, 0, 5, TimeUnit.SECONDS);
- send_d.scheduleWithFixedDelay(sendService, 0, 5, TimeUnit.SECONDS);
- }
- public static void main(String[] args) {
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- if (start()) {
- System.out.println("SMS Gateway successfully started!");
- new SampleClass();
- }
- }
- )};
- }
- /** Nested class (can be created with to class) which implements Runnable. **/
- private final Runnable recieveService = new Runnable() {
- @Override
- public void run() {
- // Throws exceptions, surround with try-catch
- super.readOut(InboundMessage.MessageClasses.ALL);
- }
- };
- private final Runnable sendService = new Runnable() {
- @Override
- public void run() {
- // Create action here
- /* Psuedo code - processing SMS messages */
- /*
- Check for new messages - read(class) or readIM(class)
- // Throws exceptions, surround with try-catch
- for (InboundMessage msg : read(class)) {
- if (msg.getText().equalsIgnoreCase("BAL")) {
- super.send(msg.getOriginator(), "Your current balance is ...");
- }
- // Other commands
- }
- */
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment