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  package org.apache.jetspeed.aggregator;
18  
19  import javax.servlet.http.HttpServletRequest;
20  import javax.servlet.http.HttpServletResponse;
21  
22  import org.apache.jetspeed.om.page.ContentFragment;
23  import org.apache.jetspeed.request.RequestContext;
24  import org.apache.pluto.om.portlet.PortletDefinition;
25  import org.apache.pluto.om.window.PortletWindow;
26  
27  
28  /***
29   * MockRenderJob
30   * 
31   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
32   * @version $Id: $
33   */
34  
35  public class MockRenderJob  implements RenderingJob
36  {
37      private long mockTime;
38      private String jobName;
39      private PortletWindow window;
40  
41      protected long startTimeMillis = 0;
42      protected long timeout;
43      
44      public MockRenderJob(String jobName, long mockTime, PortletWindow window)
45      {
46          this.mockTime = mockTime;
47          this.jobName = jobName;
48          this.window = window;
49      }
50  
51      /***
52       * Sets portlet timout in milliseconds.
53       */
54      public void setTimeout(long timeout) {
55          this.timeout = timeout;
56      }
57  
58      /***
59       * Gets portlet timout in milliseconds.
60       */
61      public long getTimeout() {
62          return this.timeout;
63      }
64  
65      /***
66       * Checks if the portlet rendering is timeout
67       */
68      public boolean isTimeout() {
69          if ((this.timeout > 0) && (this.startTimeMillis > 0)) {
70              return (System.currentTimeMillis() - this.startTimeMillis > this.timeout);
71          }
72  
73          return false;
74      }
75      
76      public void run()
77      {       
78          if (this.timeout > 0) {
79              this.startTimeMillis = System.currentTimeMillis();
80          }
81  
82          execute();
83      }
84      
85      /* (non-Javadoc)
86       * @see org.apache.jetspeed.aggregator.RenderingJob#execute()
87       */
88      public void execute()
89      {
90          System.out.println("Running mock rendering job ..." + jobName);
91          try
92          {
93              Thread.sleep(mockTime);
94          }
95          catch (InterruptedException e)
96          {
97              System.out.println("Interrupted job..." + jobName);
98          }
99          System.out.println("mock job completed " + jobName);
100     }
101 
102     /* (non-Javadoc)
103      * @see org.apache.jetspeed.aggregator.RenderingJob#getWindow()
104      */
105     public PortletWindow getWindow()
106     {
107         // TODO Auto-generated method stub
108         return window;
109     }
110 
111     /* (non-Javadoc)
112      * @see org.apache.jetspeed.aggregator.RenderingJob#getPortletContent()
113      */
114     public PortletContent getPortletContent()
115     {
116         // TODO Auto-generated method stub
117         return null;
118     }
119 
120     public ContentDispatcherCtrl getDispatcher()
121     {
122         // TODO Auto-generated method stub
123         return null;
124     }
125 
126     public int getExpirationCache()
127     {
128         // TODO Auto-generated method stub
129         return 0;
130     }
131 
132     public ContentFragment getFragment()
133     {
134         // TODO Auto-generated method stub
135         return null;
136     }
137 
138     public PortletDefinition getPortletDefinition()
139     {
140         // TODO Auto-generated method stub
141         return null;
142     }
143 
144     public HttpServletRequest getRequest()
145     {
146         // TODO Auto-generated method stub
147         return null;
148     }
149 
150     public RequestContext getRequestContext()
151     {
152         // TODO Auto-generated method stub
153         return null;
154     }
155 
156     public HttpServletResponse getResponse()
157     {
158         // TODO Auto-generated method stub
159         return null;
160     }
161 
162     public boolean isContentCached()
163     {
164         // TODO Auto-generated method stub
165         return false;
166     }
167 
168     public Object getWorkerAttribute(String name)
169     {
170         // TODO Auto-generated method stub
171         return null;
172     }
173 
174     public void removeWorkerAttribute(String name)
175     {
176         // TODO Auto-generated method stub
177     }
178 
179     public void setWorkerAttribute(String name, Object value)
180     {
181         // TODO Auto-generated method stub
182     }
183 }