summaryrefslogtreecommitdiff
path: root/qpid/java/management/console/src/main/java/org/apache/qpid/console/Agent.java
blob: e1887d82ea7fe19181e00f0b048c4dbd6ba86d3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */
package org.apache.qpid.console;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Agent
{
    private static Logger log = LoggerFactory.getLogger(Agent.class);

    public static String AgentKey(long AgentBank, long BrokerBank)
    {
        return String.format("%s:%s", AgentBank, BrokerBank);
    }

    public static long getAgentBank(String routingKey)
    {
        String delim = ".";
        return Long.parseLong(routingKey.split(java.util.regex.Pattern
                .quote(delim))[3]);
    }

    public static long getBrokerBank(String routingKey)
    {
        String delim = ".";
        return Long.parseLong(routingKey.split(java.util.regex.Pattern
                .quote(delim))[2]);
    }

    public static String routingCode(long AgentBank, long BrokerBank)
    {
        return String.format("agent.%s.%s", BrokerBank, AgentBank);
    }

    private long agentBank;
    private Broker broker;
    private long brokerBank;
    private String label;

    public Agent(Broker broker, long agentBank, String label)
    {
        this.setBroker(broker);
        this.setBrokerBank(broker.brokerBank());
        this.setAgentBank(agentBank);
        this.setlabel(label);
    }

    public final String agentKey()
    {
        return Agent.AgentKey(getAgentBank(), getBrokerBank());
    }

    public final long getAgentBank()
    {
        return agentBank;
    }

    public final Broker getBroker()
    {
        return broker;
    }

    public final long getBrokerBank()
    {
        return brokerBank;
    }

    public final String getlabel()
    {
        return label;
    }

    public final String routingCode()
    {
        return Agent.routingCode(getAgentBank(), getBrokerBank());
    }

    public final void setAgentBank(long value)
    {
        agentBank = value;
    }

    public final void setBroker(Broker value)
    {
        broker = value;
    }

    public final void setBrokerBank(long value)
    {
        brokerBank = value;
    }

    public final void setlabel(String value)
    {
        label = value;
    }
}