1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 module hunt.pool.impl.DefaultPooledObjectInfo;
18 
19 import hunt.pool.impl.DefaultPooledObjectInfoMBean;
20 // import java.io.PrintWriter;
21 // import java.io.StringWriter;
22 // import java.text.SimpleDateFormat;
23 
24 import hunt.Exceptions;
25 import hunt.util.StringBuilder;
26 
27 import hunt.pool.PooledObject;
28 
29 /**
30  * Implementation of object that is used to provide information on pooled
31  * objects via JMX.
32  *
33  */
34 class DefaultPooledObjectInfo : DefaultPooledObjectInfoMBean {
35 
36     private IPooledObject pooledObject;
37 
38     /**
39      * Create a new instance for the given pooled object.
40      *
41      * @param pooledObject The pooled object that this instance will represent
42      */
43     this(IPooledObject pooledObject) {
44         this.pooledObject = pooledObject;
45     }
46 
47     override
48     long getCreateTime() {
49         return pooledObject.getCreateTime();
50     }
51 
52     override
53     string getCreateTimeFormatted() {
54         // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
55         // return sdf.format(Long.valueOf(pooledObject.getCreateTime()));
56         
57         implementationMissing(false);
58         return "";
59     }
60 
61     override
62     long getLastBorrowTime() {
63         return pooledObject.getLastBorrowTime();
64     }
65 
66     override
67     string getLastBorrowTimeFormatted() {
68         // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
69         // return sdf.format(Long.valueOf(pooledObject.getLastBorrowTime()));
70         
71         implementationMissing(false);
72         return "";
73     }
74 
75     override
76     string getLastBorrowTrace() {
77         // StringWriter sw = new StringWriter();
78         // pooledObject.printStackTrace(new PrintWriter(sw));
79         // return sw.toString();
80         implementationMissing(false);
81         return "";
82     }
83 
84     override
85     long getLastReturnTime() {
86         return pooledObject.getLastReturnTime();
87     }
88 
89     override
90     string getLastReturnTimeFormatted() {
91         // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
92         // return sdf.format(Long.valueOf(pooledObject.getLastReturnTime()));
93         
94         implementationMissing(false);
95         return "";
96     }
97 
98     override
99     string getPooledObjectType() {
100         return pooledObject.objectType.toString();
101         // return typeid(pooledObject.getObject()).name;
102     }
103 
104     override
105     string getPooledObjectToString() {
106         return pooledObject.objectToString();
107     }
108 
109     override
110     long getBorrowedCount() {
111         implementationMissing(false);
112         // TODO Simplify this once getBorrowedCount has been added to PooledObject
113         // if (pooledObject instanceof DefaultPooledObject) {
114         //     return ((DefaultPooledObject<?>) pooledObject).getBorrowedCount();
115         // }
116         return -1;
117     }
118 
119     /**
120      */
121     override
122     string toString() {
123         StringBuilder builder = new StringBuilder();
124         builder.append("DefaultPooledObjectInfo [pooledObject=");
125         builder.append(pooledObject.toString());
126         builder.append("]");
127         return builder.toString();
128     }
129 }