FileDocCategorySizeDatePackage
SystemServiceConnectionImpl.javaAPI DocphoneME MR2 API (J2ME)3581Wed May 02 18:00:10 BST 2007com.sun.midp.services

SystemServiceConnectionImpl

public final class SystemServiceConnectionImpl extends Object implements SystemServiceConnection

Fields Summary
private SystemServiceConnectionLinks
connectionLinks
private SystemServiceConnectionListener
listener
Constructors Summary
SystemServiceConnectionImpl(SystemServiceConnectionLinks connectionLinks)

        this.connectionLinks = connectionLinks;
    
Methods Summary
public SystemServiceMessagereceive()


        try { 
            Link receiveLink = connectionLinks.getReceiveLink();
            LinkMessage msg = receiveLink.receive(); 
            byte[] data = msg.extractData();

            return new SystemServiceReadMessage(data);
        } catch (ClosedLinkException e) {
            throw new SystemServiceConnectionClosedException();
        } catch (InterruptedIOException e) {
            connectionLinks.close();
            throw new SystemServiceConnectionClosedException();
        } catch (IOException e) {
            connectionLinks.close();
            throw new SystemServiceConnectionClosedException();
        }
    
public voidsend(SystemServiceMessage msg)


        try {
            SystemServiceWriteMessage writeMsg = (SystemServiceWriteMessage)msg;
            byte[] data = writeMsg.getData();

            LinkMessage linkMsg = LinkMessage.newDataMessage(data);
            Link sendLink = connectionLinks.getSendLink();
            sendLink.send(linkMsg);
        } catch (ClosedLinkException e) {
            throw new SystemServiceConnectionClosedException();
        } catch (InterruptedIOException e) {
            connectionLinks.close();
            throw new SystemServiceConnectionClosedException();
        } catch (IOException e) {
            connectionLinks.close();
            throw new SystemServiceConnectionClosedException();
        }        
    
public voidsetConnectionListener(SystemServiceConnectionListener l)

        listener = l;
        new ListenerThread().start();