Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.conversation » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements. See the NOTICE file distributed with this
    4    * work for additional information regarding copyright ownership. The ASF
    5    * licenses this file to You under the Apache License, Version 2.0 (the
    6    * "License"); you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
    9    * or agreed to in writing, software distributed under the License is
   10    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   11    * KIND, either express or implied. See the License for the specific language
   12    * governing permissions and limitations under the License.
   13    */
   14   package org.apache.webbeans.conversation;
   15   
   16   import javax.enterprise.context.Conversation;
   17   import javax.enterprise.context.ConversationScoped;
   18   
   19   import org.apache.webbeans.container.BeanManagerImpl;
   20   import org.apache.webbeans.context.ConversationContext;
   21   import org.apache.webbeans.util.Asserts;
   22   import org.apache.webbeans.util.StringUtil;
   23   
   24   public class ConversationImpl implements Conversation
   25   {
   26       private String id;
   27   
   28       private boolean longRunning = false;
   29   
   30       private long timeout;
   31   
   32       private String sessionId;
   33   
   34       private long activeTime = 0L;
   35   
   36       public ConversationImpl()
   37       {
   38   
   39       }
   40   
   41       public ConversationImpl(String sessionId)
   42       {
   43           Asserts.assertNotNull(sessionId);
   44           this.sessionId = sessionId;
   45   
   46       }
   47   
   48       public void begin()
   49       {
   50           this.longRunning = true;
   51           this.id = StringUtil.generateUUIDStringWithoutDash();
   52   
   53           ConversationManager.getInstance().addConversationContext(this, (ConversationContext) BeanManagerImpl.getManager().getContext(ConversationScoped.class));
   54       }
   55   
   56       public void begin(String id)
   57       {
   58           this.longRunning = true;
   59           this.id = id;
   60   
   61           ConversationManager.getInstance().addConversationContext(this, (ConversationContext) BeanManagerImpl.getManager().getContext(ConversationScoped.class));
   62       }
   63   
   64       public void end()
   65       {
   66           this.longRunning = false;
   67           
   68           ConversationManager.getInstance().removeConversation(this);
   69       }
   70   
   71       public String getId()
   72       {
   73           return this.id;
   74       }
   75   
   76       public long getTimeout()
   77       {
   78           return this.timeout;
   79       }
   80   
   81       public boolean isLongRunning()
   82       {
   83           return this.longRunning;
   84       }
   85   
   86       public void setTimeout(long milliseconds)
   87       {
   88           this.timeout = milliseconds;
   89       }
   90   
   91       public String getSessionId()
   92       {
   93           return this.sessionId;
   94       }
   95   
   96       /**
   97        * @return the creationTime
   98        */
   99       public long getActiveTime()
  100       {
  101           return activeTime;
  102       }
  103   
  104   
  105       public void updateTimeOut()
  106       {
  107           this.activeTime = System.currentTimeMillis();
  108       }
  109   
  110       /*
  111        * (non-Javadoc)
  112        * @see java.lang.Object#hashCode()
  113        */
  114       @Override
  115       public int hashCode()
  116       {
  117           final int prime = 31;
  118           int result = 1;
  119           result = prime * result + ((id == null) ? 0 : id.hashCode());
  120           result = prime * result + ((sessionId == null) ? 0 : sessionId.hashCode());
  121           return result;
  122       }
  123   
  124       /*
  125        * (non-Javadoc)
  126        * @see java.lang.Object#equals(java.lang.Object)
  127        */
  128       @Override
  129       public boolean equals(Object obj)
  130       {
  131           if (this == obj)
  132               return true;
  133           if (obj == null)
  134               return false;
  135           if (getClass() != obj.getClass())
  136               return false;
  137           final ConversationImpl other = (ConversationImpl) obj;
  138           if (id == null)
  139           {
  140               if (other.id != null)
  141                   return false;
  142           }
  143           else if (!id.equals(other.id))
  144               return false;
  145           if (sessionId == null)
  146           {
  147               if (other.sessionId != null)
  148                   return false;
  149           }
  150           else if (!sessionId.equals(other.sessionId))
  151               return false;
  152           return true;
  153       }
  154   
  155   }

Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.conversation » [javadoc | source]