/*
 * Copyright to the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.rioproject.resources.servicecore;

import net.jini.core.lease.Lease;
import net.jini.id.Uuid;
import net.jini.id.UuidFactory; 
import com.sun.jini.landlord.LeasedResource;

/**
 * Leased service resources to be used with <code>LeaseDurationPolicy</code> and/or
 * <code>LeaseManager</code>
 *
 * @author Dennis Reedy
 */
public class ServiceResource implements LeasedResource {
    protected Uuid cookie;
    protected long expiration;
    public Lease lease;
    public Object resource;

    /**
     * Create a ServiceResource
     * 
     * @param resource The resource being leased
     */
    public ServiceResource(Object resource) {
        this.resource = resource;
        synchronized(ServiceResource.class) {
            cookie = UuidFactory.generate();
        }
    }

    /**
     * Returns the expiration time of the leased resource.
     * 
     * @return The expiration time in milliseconds since the beginning of the epoch
     */
    public long getExpiration() {
        return(expiration);
    }

    /**
     * Changes the expiration time of the leased resource.
     * 
     * @param expiration The new expiration time in milliseconds since the beginning of 
     * the epoch
     */
    public void setExpiration(long expiration) {
        this.expiration = expiration;
    }

    /**
     * Returns a unique identifier that can be used by the grantor of
     * the resource to identify it
     */
    public Uuid getCookie() {
        return(cookie);
    }

    /**
     * Returns the resource that is being leased
     *
     * @return The actual resource
     */
    public Object getResource() {
        return(resource);
    }

    /**
     * Overrides <code>equals()</code> to be based on the value of the cookie attribute
     */
    public boolean equals(Object o) {
        if(o instanceof ServiceResource) {
            ServiceResource sr = (ServiceResource)o;
            return(cookie.equals(sr.cookie));
        }
        return(false);
    }

    /**
     * Overrides <code>hashcode()</code> to be based on the hashcode of the 
     * cookie attribute
     */
    public int hashCode() {
        return(cookie.hashCode());
    }
}

@@ -665,32 +665,43 @@
 ort 
-net.jini.core.lease.Leas
+com.sun.jini.landlord.LeasedResourc
 e;%0Ai
@@ -759,54 +759,8 @@
 ory;
- %0Aimport com.sun.jini.landlord.LeasedResource;
 %0A%0A/*
@@ -968,23 +968,21 @@
 %7B%0A    pr
-otec
+iva
 te
-d
  Uuid co
@@ -997,15 +997,13 @@
   pr
-otected
+ivate
  lon
@@ -1025,37 +1025,20 @@
    p
-ublic Lease lease;%0A    public
+rivate final
  Obj
@@ -1184,16 +1184,22 @@
 esource(
+final 
 Object r
@@ -1566,17 +1566,17 @@
   return
-(
+ 
 expirati
@@ -1577,17 +1577,16 @@
 piration
-)
 ;%0A    %7D%0A
@@ -2038,16 +2038,15 @@
 turn
-(
+ 
 cookie
-)
 ;%0A  
@@ -2209,17 +2209,17 @@
 turn
-(
+ 
 resource
 );%0A 
@@ -2214,17 +2214,16 @@
 resource
-)
 ;%0A    %7D%0A
@@ -2535,15 +2535,14 @@
 turn
-(
+ 
 false
-)
 ;%0A  
@@ -2701,25 +2701,25 @@
       return
-(
+ 
 cookie.hashC
@@ -2723,17 +2723,16 @@
 shCode()
-)
 ;%0A    %7D%0A

Make properties final