Package org.apache.activemq.partition.dto

Examples of org.apache.activemq.partition.dto.Target


    }

    protected void checkTarget(ConnectionMonitor monitor) {

        // can we find a preferred target for the connection?
        Target targetDTO = pickBestBroker(monitor);
        if( targetDTO == null || targetDTO.ids==null) {
            LOG.debug("No partition target found for connection: "+monitor.context.getConnectionId());
            return;
        }
View Full Code Here


            Socket socket = transport.narrow(Socket.class);
            if( socket !=null ) {
                SocketAddress address = socket.getRemoteSocketAddress();
                if( address instanceof InetSocketAddress) {
                    String ip = ((InetSocketAddress) address).getAddress().getHostAddress();
                    Target targetDTO = getConfig().bySourceIp.get(ip);
                    if( targetDTO!=null ) {
                        return targetDTO;
                    }
                }
            }
        }

        if( getConfig().byUserName !=null && !getConfig().byUserName.isEmpty() ) {
            String userName = monitor.context.getUserName();
            if( userName !=null ) {
                Target targetDTO = getConfig().byUserName.get(userName);
                if( targetDTO!=null ) {
                    return targetDTO;
                }
            }
        }

        if( getConfig().byClientId !=null && !getConfig().byClientId.isEmpty() ) {
            String clientId = monitor.context.getClientId();
            if( clientId!=null ) {
                Target targetDTO = getConfig().byClientId.get(clientId);
                if( targetDTO!=null ) {
                    return targetDTO;
                }
            }
        }

        if(
             (getConfig().byQueue !=null && !getConfig().byQueue.isEmpty())
          || (getConfig().byTopic !=null && !getConfig().byTopic.isEmpty())
          ) {

            // Collect the destinations the connection is consuming from...
            HashSet<ActiveMQDestination> dests = new HashSet<ActiveMQDestination>();
            for (SessionState session : monitor.context.getConnectionState().getSessionStates()) {
                for (ConsumerState consumer : session.getConsumerStates()) {
                    ActiveMQDestination destination = consumer.getInfo().getDestination();
                    if( destination.isComposite() ) {
                        dests.addAll(Arrays.asList(destination.getCompositeDestinations()));
                    } else {
                        dests.addAll(Collections.singletonList(destination));
                    }
                }
            }

            // Group them by the partitioning target for the destinations and score them..
            HashMap<Target, Score> targetScores = new HashMap<Target, Score>();
            for (ActiveMQDestination dest : dests) {
                Target target = getTarget(dest);
                if( target!=null ) {
                    Score score = targetScores.get(target);
                    if( score == null ) {
                        score = new Score();
                        targetScores.put(target, score);
                    }
                    score.value++;
                }
            }

            // The target with largest score wins..
            if( !targetScores.isEmpty() ) {
                Target bestTarget = null;
                int bestScore=0;
                for (Map.Entry<Target, Score> entry : targetScores.entrySet()) {
                    if( entry.getValue().value > bestScore ) {
                        bestTarget = entry.getKey();
                    }
                }
                return bestTarget;
            }

            // If we get here is because there were no consumers, or the destinations for those
            // consumers did not have an assigned destination..  So partition based on producer
            // usage.
            Target best = monitor.findBestProducerTarget(this);
            if( best!=null ) {
                return best;
            }
        }
        return null;
View Full Code Here

        public ConnectionMonitor(ConnectionContext context) {
            this.context = context;
        }

        synchronized public Target findBestProducerTarget(PartitionBroker broker) {
            Target best = null;
            long bestSize = 0 ;
            for (Map.Entry<ActiveMQDestination, Traffic> entry : trafficPerDestination.entrySet()) {
                Traffic t = entry.getValue();
                // Once we get enough messages...
                if( t.messages < broker.plugin.getMinTransferCount()) {
                    continue;
                }
                if( t.bytes > bestSize) {
                    bestSize = t.bytes;
                    Target target = broker.getTarget(entry.getKey());
                    if( target!=null ) {
                        best = target;
                    }
                }
            }
View Full Code Here

     */
    @Test(timeout = 1000*60*60)
    public void testNonFailoverClientHasNoPartitionEffect() throws Exception {

        partitioning.byClientId = new HashMap<String, Target>();
        partitioning.byClientId.put("client1", new Target("broker1"));
        createBrokerCluster(2);

        Connection connection = createConnectionToUrl(getConnectURL("broker2"));
        within(5, TimeUnit.SECONDS, new Task() {
            public void run() throws Exception {
View Full Code Here

    }

    @Test(timeout = 1000*60*60)
    public void testPartitionByClientId() throws Exception {
        partitioning.byClientId = new HashMap<String, Target>();
        partitioning.byClientId.put("client1", new Target("broker1"));
        partitioning.byClientId.put("client2", new Target("broker2"));
        createBrokerCluster(2);

        Connection connection = createConnectionTo("broker2");

        within(5, TimeUnit.SECONDS, new Task() {
View Full Code Here

    }

    @Test(timeout = 1000*60*60)
    public void testPartitionByQueue() throws Exception {
        partitioning.byQueue = new HashMap<String, Target>();
        partitioning.byQueue.put("foo", new Target("broker1"));
        createBrokerCluster(2);

        Connection connection2 = createConnectionTo("broker2");

        within(5, TimeUnit.SECONDS, new Task() {
View Full Code Here

TOP

Related Classes of org.apache.activemq.partition.dto.Target

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.