Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jacorb.notification.servant;
  
  /*
   *        JacORB - a free Java ORB
   *
   *   Copyright (C) 1997-2012 Gerald Brose / The JacORB Team.
   *
   *   This library is free software; you can redistribute it and/or
   *   modify it under the terms of the GNU Library General Public
  *   License as published by the Free Software Foundation; either
  *   version 2 of the License, or (at your option) any later version.
  *
  *   This library 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
  *   Library General Public License for more details.
  *
  *   You should have received a copy of the GNU Library General Public
  *   License along with this library; if not, write to the Free
  *   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 import java.util.Map;
 

Author(s):
Alphonse Bendt
Jmx.mbean:
extends = "AbstractProxySupplierMBean"
Jboss.xmbean:
 
 
 public class TypedProxyPullSupplierImpl extends AbstractProxySupplier implements
 {
     private final Any trueAny_;
 
     private final Any falseAny_;
 
     private final DynAnyFactory dynAnyFactory_;
 
     private final String supportedInterface_;
 
     private PullConsumer pullConsumer_;
 
 
 
     private final Map messageQueueMap_;
 
     private final Map invalidResponses_;
 
     private final Repository repository_;
 
    private class TypedProxyPullSupplier extends DynamicImplementation
    {
        private final String[] supportedInterfaces_ = new String[] {  };
        public void invoke(final ServerRequest request)
        {
            String _operation = request.operation();
            boolean _isTryOp = false;
            if (_operation.startsWith("try_"))
            {
                _isTryOp = true;
                // cut 'try_' prefix
                _operation = _operation.substring(4);
            }
            try
            {
                final Message _mesg;
                final MessageQueueAdapter _queue = (MessageQueueAdapter
                        .get(_operation);
                if (_isTryOp)
                {
                    _mesg = _queue.getMessageNoBlock();
                }
                else
                {
                    _mesg = _queue.getMessageBlocking();
                }
                try
                {
                    final NVList _args;
                    if (_mesg == null)
                    {
                        _args = (NVList.get(_operation);
                        if (_isTryOp)
                        {
                            request.set_result();
                        }
                    }
                    else
                    {
                        _args = prepareResponse(_mesg);
                        if (_isTryOp)
                        {
                            request.set_result();
                        }
                    }
                    request.arguments(_args);
                } finally
                {
                    if (_mesg != null)
                    {
                        _mesg.dispose();
                    }
                }
            } catch (InterruptedException e)
            {
                // ignore
            }
        }
        public String[] _all_interfaces(POA poabyte[] oid)
        {
            return ;
        }
        public POA _default_POA()
        {
            return getPOA();
        }
    }
    private final NVList prepareResponse(Message mesg)
    {
        try
        {
            final Property[] _props = mesg.toTypedEvent();
            final NVList _args = getORB().create_list(_props.length - 1);
            // start at index 1 here. index 0 contains the operation name
            for (int x = 1; x < _props.length; ++x)
            {
                _args.add_value(_props[x]._props[x]..);
            }
            return _args;
        } catch (NoTranslationException e)
        {
            // cannot happen here
            // as there are no nontranslatable Messages queued.
            throw new RuntimeException();
        }
    }
    public TypedProxyPullSupplierImpl(ITypedAdmin adminConsumerAdmin consumerAdminORB orb,
            POA poaConfiguration confTaskProcessor taskProcessorOfferManager offerManager,
            SubscriptionManager subscriptionManagerDynAnyFactory dynAnyFactory,
            Repository repositorythrows ConfigurationException
    {
        super(adminorbpoaconftaskProcessorofferManager,
                subscriptionManagerconsumerAdmin);
         = orb.create_any();
         = orb.create_any();
        .insert_boolean(true);
        .insert_boolean(false);
         = admin.getSupportedInterface();
         = dynAnyFactory;
         = repository;
                new String[] { .. }, );
        try
        {
            FullInterfaceDescription interfaceDescription = getInterfaceDescription();
            validateInterface(interfaceDescription);
             = Collections
                    .unmodifiableMap(newMessageQueueMap(interfaceDescription));
             = Collections
                    .unmodifiableMap(newInvalidResponseMap(interfaceDescription));
        } catch (InconsistentTypeCode e)
        {
            throw new RuntimeException();
        }
    }
    private void ensureMethodOnlyUsesOutParams(OperationDescription operation)
            throws IllegalArgumentException
    {
        int _noOfParameters = operation.parameters.length;
        for (int x = 0; x < _noOfParameters; ++x)
        {
            switch (operation.parameters[x]..value()) {
            case .:
            // fallthrough
            case .:
                throw new IllegalArgumentException("only OUT params allowed");
            case .:
                break;
            }
        }
    }
    private void prepareInvalidResponse(Map mapOperationDescription operation)
            throws InconsistentTypeCode
    {
        final NVList _expectedParams = getORB().create_list(operation.parameters.length);
        for (int x = 0; x < operation.parameters.length; ++x)
        {
            final DynAny _dynAny = 
                    .create_dyn_any_from_type_code(operation.parameters[x].);
            _expectedParams
                    .add_value(operation.parameters[x]._dynAny.to_any(), .);
        }
        map.put(operation.name_expectedParams);
    }
    private final Map newMessageQueueMap(FullInterfaceDescription interfaceDescription)
    {
        Map map = new HashMap();
        for (int x = 0; x < interfaceDescription.operations.length; ++x)
        {
            if (!interfaceDescription.operations[x]..startsWith("try_"))
            {
                .debug("Create Queue for Operation: "
                        + interfaceDescription.operations[x].);
                MessageQueueAdapter _messageQueue =
                    getMessageQueueFactory().newMessageQueue();
                map.put(interfaceDescription.operations[x].,
                        new RWLockEventQueueDecorator(_messageQueue));
            }
        }
        return map;
    }
    private final Map newInvalidResponseMap(FullInterfaceDescription interfaceDescription)
            throws InconsistentTypeCode
    {
        Map map = new HashMap();
        for (int x = 0; x < interfaceDescription.operations.length; ++x)
        {
            if (!interfaceDescription.operations[x]..startsWith("try_"))
            {
                prepareInvalidResponse(mapinterfaceDescription.operations[x]);
            }
        }
        return map;
    }
    private final void validateInterface(FullInterfaceDescription interfaceDescription)
    {
        for (int x = 0; x < interfaceDescription.operations.length; ++x)
        {
            ensureMethodOnlyUsesOutParams(interfaceDescription.operations[x]);
        }
    }
    {
        InterfaceDef _interfaceDef = InterfaceDefHelper.narrow(
                .lookup_id());
        return _interfaceDef.describe_interface();
    }
    private final void configureEventQueue()
    {
        try
        {
            Iterator i = .keySet().iterator();
            while (i.hasNext())
            {
                String _key = (Stringi.next();
                RWLockEventQueueDecorator _queueAdapter =
                    (RWLockEventQueueDecorator.get(_key);
                MessageQueueAdapter _newQueue = getMessageQueueFactory().newMessageQueue();
                _queueAdapter.replaceDelegate(_newQueue);
            }
        } catch (InterruptedException e)
        {
            throw new RuntimeException(e.toString());
        }
    }
    public int getPendingMessagesCount()
    {
        try
        {
            Iterator i = .keySet().iterator();
            int _count = 0;
            while (i.hasNext())
            {
                String _key = (Stringi.next();
                RWLockEventQueueDecorator _queueAdapter =
                    (RWLockEventQueueDecorator.get(_key);
                _count += _queueAdapter.getPendingMessagesCount();
            }
            return _count;
        } catch (InterruptedException e)
        {
            return -1;
        }
    }
    {
        public void actionPropertySetChanged(PropertySet source)
        {
            configureEventQueue();
        }
    };
    public Any pull() throws Disconnected
    {
        throw new NO_IMPLEMENT();
    }
    public Any try_pull(BooleanHolder booleanHolderthrows Disconnected
    {
        throw new NO_IMPLEMENT();
    }
    public void disconnect_pull_supplier()
    {
        destroy();
    }
    public void connect_typed_pull_consumer(PullConsumer pullConsumerthrows AlreadyConnected
    {
        checkIsNotConnected();
        connectClient(pullConsumer);
         = pullConsumer;
    }
    {
        if ( == null)
        {
             = new TypedProxyPullSupplier();
        }
        return ;
    }
    public ProxyType MyType()
    {
        return .;
    }
    public Servant newServant()
    {
        return new TypedProxyPullSupplierPOATie(this);
    }
    public void queueMessage(Message message)
    {
        try
        {
            Property[] _props = message.toTypedEvent();
            final String _fullQualifiedOperation;
            if (..equals(_props[0].))
            {
                _fullQualifiedOperation = _props[0]..extract_string();
            }
            else if (..equals(_props[0].))
            {
                _fullQualifiedOperation = EventTypeHelper.extract(_props[0].).;
            }
            else
            {
                throw new IllegalArgumentException();
            }
            int idx = _fullQualifiedOperation.lastIndexOf("::");
            String _operation = _fullQualifiedOperation.substring(idx + 2);
            final Message _clonedMessage = (Messagemessage.clone();
            try
            {
                ((MessageQueueAdapter.get(_operation)).enqeue(_clonedMessage);
            } catch (InterruptedException e)
            {
                _clonedMessage.dispose();
            }
        } catch (NoTranslationException e)
        {
            // ignore
            // Message is not delivered to the connected Consumer
        }
    }
    public void deliverPendingData()
    {
        // No Op as this Proxy is a PullSupplier
    }
    public void disconnectClient()
    {
         = null;
    }
    protected long getCost()
    {
        return 0;
    }

    

Jmx.managed:
attribute access = "read-only"
    public String getSupportedInterface()
    {
        return ;
    }
New to GrepCode? Check out our FAQ X