1 /*
2  * hunt-proton: AMQP Protocol library for D programming language.
3  *
4  * Copyright (C) 2018-2019 HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 
12 
13 module hunt.proton.amqp.messaging.TerminusExpiryPolicy;
14 
15 import hunt.collection.HashMap;
16 import hunt.collection.Map;
17 import hunt.collection.HashMap;
18 import hunt.proton.amqp.Symbol;
19 import hunt.logging;
20 
21 class TerminusExpiryPolicy
22 {
23     __gshared TerminusExpiryPolicy LINK_DETACH ;
24     __gshared TerminusExpiryPolicy SESSION_END ;
25     __gshared TerminusExpiryPolicy CONNECTION_CLOSE ;
26     __gshared TerminusExpiryPolicy NEVER ;
27 
28     private Symbol _policy;
29     __gshared HashMap!(Symbol, TerminusExpiryPolicy) _map ;
30 
31     this(string policy)
32     {
33         _policy = Symbol.valueOf(policy);
34     }
35 
36     public Symbol getPolicy()
37     {
38         return _policy;
39     }
40 
41     shared static  this()
42     {
43         LINK_DETACH = new TerminusExpiryPolicy("link-detach");
44         SESSION_END = new TerminusExpiryPolicy("session-end");
45         CONNECTION_CLOSE = new TerminusExpiryPolicy("connection-close");
46         NEVER = new TerminusExpiryPolicy("never");
47         _map = new HashMap!(Symbol, TerminusExpiryPolicy)();
48         _map.put(LINK_DETACH.getPolicy(), LINK_DETACH);
49         _map.put(SESSION_END.getPolicy(), SESSION_END);
50         _map.put(CONNECTION_CLOSE.getPolicy(), CONNECTION_CLOSE);
51         _map.put(NEVER.getPolicy(), NEVER);
52     }
53 
54     public static TerminusExpiryPolicy valueOf(Symbol policy)
55     {
56         TerminusExpiryPolicy expiryPolicy = _map.get(policy);
57         if(expiryPolicy is null)
58         {
59             //throw new IllegalArgumentException("Unknown TerminusExpiryPolicy: " ~ policy);
60             logError("Unknown TerminusExpiryPolicy");
61         }
62         return expiryPolicy;
63     }
64 }