aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/RoutingPolicyFactories.java
blob: 6954d8f3a1d707f915b7dbc5f7fd6b4e33ccae40 (plain) (blame)
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
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentapi.messagebus.protocol;

/**
 * @author Simon Thoresen Hult
 */
public abstract class RoutingPolicyFactories {

    static class AndPolicyFactory implements RoutingPolicyFactory {
        public DocumentProtocolRoutingPolicy createPolicy(String param) {
            return new ANDPolicy(param);
        }


        public void destroy() {
        }
    }

    static class StoragePolicyFactory implements RoutingPolicyFactory {
        public DocumentProtocolRoutingPolicy createPolicy(String param) {
            return new StoragePolicy(param);
        }

        public void destroy() {
        }
    }

    static class ContentPolicyFactory implements RoutingPolicyFactory {
        public DocumentProtocolRoutingPolicy createPolicy(String param) {
            return new ContentPolicy(param);
        }

        public void destroy() {
        }
    }

    static class MessageTypePolicyFactory implements RoutingPolicyFactory {
        private final String configId;

        public MessageTypePolicyFactory(String configId) {
            this.configId = configId;
        }
        public DocumentProtocolRoutingPolicy createPolicy(String param) {
            return new MessageTypePolicy((param == null || param.isEmpty()) ? configId : param);
        }

        public void destroy() {
        }
    }

    static class DocumentRouteSelectorPolicyFactory implements RoutingPolicyFactory {

        private final String configId;

        public DocumentRouteSelectorPolicyFactory(String configId) {
            this.configId = configId;
        }

        public DocumentProtocolRoutingPolicy createPolicy(String param) {
            DocumentRouteSelectorPolicy ret = new DocumentRouteSelectorPolicy((param == null || param.isEmpty()) ?
                                                                              configId : param);
            String error = ret.getError();
            if (error != null) {
                return new ErrorPolicy(error);
            }
            return ret;
        }


        public void destroy() {
        }
    }

    static class ExternPolicyFactory implements RoutingPolicyFactory {
        public DocumentProtocolRoutingPolicy createPolicy(String param) {
            ExternPolicy ret = new ExternPolicy(param);
            String error = ret.getError();
            if (error != null) {
                return new ErrorPolicy(error);
            }
            return ret;
        }


        public void destroy() {
        }
    }

    static class LocalServicePolicyFactory implements RoutingPolicyFactory {
        public DocumentProtocolRoutingPolicy createPolicy(String param) {
            return new LocalServicePolicy(param);
        }


        public void destroy() {
        }
    }

    static class RoundRobinPolicyFactory implements RoutingPolicyFactory {
        public DocumentProtocolRoutingPolicy createPolicy(String param) {
            return new RoundRobinPolicy();
        }


        public void destroy() {
        }
    }

    static class LoadBalancerPolicyFactory implements RoutingPolicyFactory {
        public DocumentProtocolRoutingPolicy createPolicy(String param) {
            return new LoadBalancerPolicy(param);
        }


        public void destroy() {
        }
    }

    static class SubsetServicePolicyFactory implements RoutingPolicyFactory {
        public DocumentProtocolRoutingPolicy createPolicy(String param) {
            return new SubsetServicePolicy(param);
        }


        public void destroy() {
        }
    }
}