javaextensions/wma/sms_cbs/javasrc/com/nokia/mj/impl/sms/SMSConnectionImpl.java
changeset 78 71ad690e91f5
parent 21 2a9601315dfc
equal deleted inserted replaced
72:1f0034e370aa 78:71ad690e91f5
     1 /*
     1 /*
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    26 import javax.wireless.messaging.MessageListener;
    26 import javax.wireless.messaging.MessageListener;
    27 import javax.wireless.messaging.MessageConnection;
    27 import javax.wireless.messaging.MessageConnection;
    28 
    28 
    29 import com.nokia.mj.impl.utils.Logger;
    29 import com.nokia.mj.impl.utils.Logger;
    30 import com.nokia.mj.impl.smscbs.utils.WmaUrl;
    30 import com.nokia.mj.impl.smscbs.utils.WmaUrl;
    31 import com.nokia.mj.impl.rt.support.ShutdownListener;
    31 import com.nokia.mj.impl.rt.support.Finalizer;
    32 import com.nokia.mj.impl.rt.support.ApplicationUtils;
    32 import com.nokia.mj.impl.rt.support.ApplicationUtils;
    33 /**
    33 /**
    34  * The SMSConnectionImpl used for sending and receiving Binary/Text Messages. It
    34  * The SMSConnectionImpl used for sending and receiving Binary/Text Messages. It
    35  * offers methods for creating Binary/Text Messages and for sending them. It
    35  * offers methods for creating Binary/Text Messages and for sending them. It
    36  * implements the receiving functionality.
    36  * implements the receiving functionality.
    94 
    94 
    95     // the listener used for messages receiving notifications
    95     // the listener used for messages receiving notifications
    96     private MessageListener iMessageListener;
    96     private MessageListener iMessageListener;
    97 
    97 
    98     private WmaUrl iUri;
    98     private WmaUrl iUri;
       
    99     
       
   100     private Finalizer iFinalizer;
    99 
   101 
   100     public SMSConnectionImpl(WmaUrl aMsgUri, boolean aServerMode)
   102     public SMSConnectionImpl(WmaUrl aMsgUri, boolean aServerMode)
   101     throws IOException
   103     throws IOException
   102     {
   104     {
   103         Logger.LOG(Logger.EWMA, Logger.EInfo,
   105         Logger.LOG(Logger.EWMA, Logger.EInfo,
   111         iReadLock = new Object();
   113         iReadLock = new Object();
   112         iWriteLock = new Object();
   114         iWriteLock = new Object();
   113         iCloseLock = new Object();
   115         iCloseLock = new Object();
   114         iMessageLock = new Object();
   116         iMessageLock = new Object();
   115         iSendLock = new Object();
   117         iSendLock = new Object();
   116         //register for shutdown listening
   118         //register for Finalization
   117         setShutdownListener();
   119         iFinalizer = registerForFinalization();
   118         Logger.LOG(Logger.EWMA, Logger.EInfo,
   120         Logger.LOG(Logger.EWMA, Logger.EInfo,
   119                    "- SMSConnectionImpl::SMSConnectionImpl");
   121                    "- SMSConnectionImpl::SMSConnectionImpl");
   120     }
   122     }
   121 
   123 
   122     /*
   124     /*
   123      * This function registers this object for shutDown.
   125      * This function registers for Finalization.
   124      */
   126      */
   125     private void setShutdownListener()
   127 
   126     {
   128 
   127         Logger.LOG(Logger.EWMA, Logger.EInfo,
   129     public Finalizer registerForFinalization()
   128                    "+ SMSConnectionImpl::setShutdownListener");
   130     {
   129         // Get the insatnce of ApplicationUtils.
   131         return new Finalizer()
   130         ApplicationUtils appUtils = ApplicationUtils.getInstance();
   132         {
   131 
   133             public void finalizeImpl()
   132         // Get the name of the application.
       
   133         appUtils.addShutdownListener(new ShutdownListener()
       
   134         {
       
   135             //The method that gets called when Application is shutting down
       
   136             public void shuttingDown()
       
   137             {
   134             {
   138                 try
   135                 try
   139                 {
   136                 {
   140                     close();
   137                     close();
   141                 }
   138                 }
   142                 catch (IOException ex)
   139                 catch (IOException e)
   143                 {
   140                 {
   144                     //Nothing to do, just ignore
   141                     //Nothing to do, just ignore
   145                     Logger.ELOG(Logger.EWMA, ex.toString(), ex);
   142                     Logger.LOG(Logger.EWMA, Logger.EInfo, e.toString());
   146                 }
   143                 }
   147             }
   144             }
   148         });
   145         };
   149         Logger.LOG(Logger.EWMA, Logger.EInfo,
       
   150                    "- SMSConnectionImpl::setShutdownListener");
       
   151     }
   146     }
   152 
   147 
   153     /**
   148     /**
   154      * open() is only called when a MIDlet calls Connector.open() a MIDlet will
   149      * open() is only called when a MIDlet calls Connector.open() a MIDlet will
   155      * not be able to access the Connection until open() has completed and a
   150      * not be able to access the Connection until open() has completed and a