alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Jetty example source code file (LocalStore.java)

This example Jetty source code file (LocalStore.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Jetty tags/keywords

exception, exception, http, localstate, localstore, localstore, logger, manager, manager, map, object, request, response, servlet, state, state, store, string, util

The Jetty LocalStore.java source code

// ========================================================================
// $Id: LocalStore.java,v 1.4 2004/05/09 20:30:47 gregwilkins Exp $
// Copyright 2002-2004 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// 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.mortbay.j2ee.session;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.jboss.logging.Logger;

//----------------------------------------

public class LocalStore implements Store
{
    protected static final Logger _log = Logger.getLogger(LocalStore.class);

    Map _sessions = new HashMap();

    protected Manager _manager;

    public Manager getManager()
    {
        return _manager;
    }

    public void setManager(Manager manager)
    {
        _manager = manager;
    }

    // Store LifeCycle
    public void start()
    {
    }

    public void stop()
    {
    }

    public void destroy()
    {
    }

    // State LifeCycle
    public State newState(String id, int maxInactiveInterval)
    {
        return new LocalState(id, maxInactiveInterval,
                _actualMaxInactiveInterval);
    }

    public State loadState(String id)
    {
        synchronized (_sessions)
        {
            return (State) _sessions.get(id);
        }
    }

    public void storeState(State state)
    {
        try
        {
            synchronized (_sessions)
            {
                _sessions.put(state.getId(), state);
            }
        }
        catch (Exception e)
        {
            _log.warn("could not store session");
        }
    }

    public void removeState(State state)
    {
        try
        {
            synchronized (_sessions)
            {
                _sessions.remove(state.getId());
            }
        }
        catch (Exception e)
        {
            _log.error("could not remove session", e);
        }
    }

    public String allocateId(HttpServletRequest request)
    {
        return getManager().getIdGenerator().nextId(request);
    }

    public void deallocateId(String id)
    {
    }

    public boolean isDistributed()
    {
        return false;
    }

    public void passivateSession(StateAdaptor sa)
    {
        // we don't do that !
        sa.invalidate();
    }

    // there is no need to scavenge distributed state - as there is none.
    public void setScavengerPeriod(int period)
    {
    }

    public void setScavengerExtraTime(int time)
    {
    }

    public void scavenge()
    {
    }

    protected int _actualMaxInactiveInterval = 0;

    public void setActualMaxInactiveInterval(int interval)
    {
        _actualMaxInactiveInterval = interval;
    }

    public int getActualMaxInactiveInterval()
    {
        return _actualMaxInactiveInterval;
    }

    public Object clone()
    {
        LocalStore ls = new LocalStore();
        ls.setActualMaxInactiveInterval(_actualMaxInactiveInterval);
        return ls;
    }
}

Other Jetty examples (source code examples)

Here is a short list of links related to this Jetty LocalStore.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.