View Javadoc

1   /*
2    * Copyright 1999-2005 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.struts.flow.core;
17  
18  import java.text.SimpleDateFormat;
19  import java.util.ArrayList;
20  import java.util.Date;
21  import java.util.Iterator;
22  import java.util.List;
23  
24  /***
25   * Access to continuation data for monitoring applications
26   */
27  public class WebContinuationDataBean {
28  
29      private static final String TYPE_JAVAFLOW = "javaflow";
30      private static final String TYPE_FLOWSCRIPT = "flowscript";
31      private static final String HAS_EXPIRED_NO = "no";
32      private static final String HAS_EXPIRED_YES = "yes";
33  
34      private WebContinuation wc;
35      private SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
36      private List _children = new ArrayList();
37  
38      public WebContinuationDataBean(WebContinuation wc) {
39          this.wc = wc;
40          for (Iterator it = wc.getChildren().iterator(); it.hasNext();) {
41              WebContinuationDataBean child = new WebContinuationDataBean(
42                      (WebContinuation) it.next());
43              this._children.add(child);
44          }
45      }
46  
47      public String getId() {
48          return wc.getId();
49      }
50  
51      public String getLastAccessTime() {
52          return formatter.format(new Date(wc.getLastAccessTime()));
53      }
54  
55      public String getInterpreterId() {
56          return wc.getInterpreterId();
57      }
58  
59      public String getTimeToLiveInMinutes() {
60          return Long.toString(wc.getTimeToLive() / 1000 / 60);
61      }
62  
63      public String getTimeToLive() {
64          return Long.toString(wc.getTimeToLive());
65      }
66  
67      public String getExpireTime() {
68          return formatter.format(new Date(wc.getLastAccessTime()
69                  + wc.getTimeToLive()));
70      }
71  
72      public String hasExpired() {
73          if ((wc.getLastAccessTime() + wc.getTimeToLive()) < System
74                  .currentTimeMillis()) {
75              return HAS_EXPIRED_YES;
76          }
77          return HAS_EXPIRED_NO;
78  
79      }
80  
81      public String getType() {
82          if (wc.getUserObject().getClass().getName().indexOf(
83                  "FOM_WebContinuation") > 0) {
84              return TYPE_FLOWSCRIPT;
85          }
86          return TYPE_JAVAFLOW;
87      }
88  
89      public List get_children() {
90          return this._children;
91      }
92  
93  }