Example usage for org.apache.wicket Application getMetaData

List of usage examples for org.apache.wicket Application getMetaData

Introduction

In this page you can find the example usage for org.apache.wicket Application getMetaData.

Prototype

public final synchronized <T> T getMetaData(final MetaDataKey<T> key) 

Source Link

Document

Gets metadata for this application using the given key.

Usage

From source file:org.wicketstuff.chat.channel.TimerChannelBehavior.java

License:Apache License

/**
 * Cleans the metadata (triggers, poll time) associated with a given
 * behavior id/*from  w w w .j  a va 2s  . c o  m*/
 * 
 * @param application
 *            the application in which the metadata are stored
 * @param id
 *            the id of the behavior
 */
private static void cleanMetadata(final Application application, String id) {
    id = getPageId(application, id);
    ConcurrentMap<String, List<DelayedMethodCallList>> triggersById = null;
    ConcurrentMap<String, Time> eventsTimeById = null;
    ConcurrentMap<String, String> pageIdsById = null;
    synchronized (application) {
        triggersById = application.getMetaData(TRIGGERS_KEY);
        eventsTimeById = application.getMetaData(EVENTS_KEY);
        pageIdsById = application.getMetaData(PAGE_ID_KEY);
    }
    if (triggersById != null) {
        final List<DelayedMethodCallList> triggers = triggersById.remove(id);
        if (triggers != null) {
            synchronized (triggers) {
                triggers.clear();
            }
        }
    }
    if (eventsTimeById != null) {
        eventsTimeById.remove(id);
    }
    if (pageIdsById != null) {
        pageIdsById.remove(id);
    }
}

From source file:org.wicketstuff.chat.channel.TimerChannelBehavior.java

License:Apache License

private static void touch(final Application application, String id) {
    id = getPageId(application, id);//from  ww  w. jav  a  2s.c  om
    ConcurrentMap<String, Time> eventsTimeById;
    synchronized (application) {
        eventsTimeById = application.getMetaData(EVENTS_KEY);
        if (eventsTimeById == null) {
            eventsTimeById = new ConcurrentHashMap<String, Time>();
            application.setMetaData(EVENTS_KEY, eventsTimeById);
        }
    }
    eventsTimeById.put(id, Time.now());
}

From source file:org.wicketstuff.chat.channel.TimerChannelBehavior.java

License:Apache License

private static Time getLastPollEvent(final Application application, String id) {
    id = getPageId(application, id);//  w w w  .ja va2 s . c  om
    ConcurrentMap<String, Time> eventsTimeById;
    synchronized (application) {
        eventsTimeById = application.getMetaData(EVENTS_KEY);
        if (eventsTimeById == null) {
            return null;
        }
    }
    final Time time = eventsTimeById.get(id);
    return time;
}

From source file:org.wicketstuff.chat.channel.TimerChannelBehavior.java

License:Apache License

/**
 * Returns the page behavior id corresponding the given behavior id. Only
 * one behavior is actually rendered on a page for the same updateInterval,
 * to optimize the number of requests. Therefore all timer channel behaviors
 * of the same page are redirected to the same id, using this method.
 * //from   w w  w.j a v  a  2  s  .c  o m
 * @param application
 *            the wicket application to which the behavior belong
 * @param id
 *            the id of the behavior for which the page behavior id should
 *            be found
 * @return the page behavior id corresponding the given behavior id.
 */
private static String getPageId(final Application application, final String id) {
    ConcurrentMap<String, String> pageIdsById;
    synchronized (application) {
        pageIdsById = application.getMetaData(PAGE_ID_KEY);
        if (pageIdsById == null) {
            return id;
        }
    }
    final String pageId = pageIdsById.get(id);
    return pageId == null ? id : pageId;
}

From source file:org.wicketstuff.chat.channel.TimerChannelBehavior.java

License:Apache License

private static void setRedirectId(final Application application, final String id, final String redirectedId) {
    ConcurrentMap<String, String> pageIdsById;
    synchronized (application) {
        pageIdsById = application.getMetaData(PAGE_ID_KEY);
        if (pageIdsById == null) {
            pageIdsById = new ConcurrentHashMap<String, String>();
            application.setMetaData(PAGE_ID_KEY, pageIdsById);
        }/*from   w  ww .  j  a  v  a2s .  c  om*/
    }
    final String oldRedirectedId = pageIdsById.put(id, redirectedId);
    if (!redirectedId.equals(oldRedirectedId)) {
        /*
         * The id was not already redirected to the redirectedId, we need to
         * merge the information before redirection with information after
         * redirection
         */
        final String idToRedirect = oldRedirectedId == null ? id : oldRedirectedId;
        redirect(application, idToRedirect, redirectedId);
    }
}

From source file:org.wicketstuff.chat.channel.TimerChannelBehavior.java

License:Apache License

private static void redirect(final Application application, final String idToRedirect,
        final String redirectedId) {
    ConcurrentMap<String, List<DelayedMethodCallList>> triggersById = null;
    ConcurrentMap<String, Time> eventsTimeById = null;
    synchronized (application) {
        triggersById = application.getMetaData(TRIGGERS_KEY);
        eventsTimeById = application.getMetaData(EVENTS_KEY);
    }/*from  w  w  w. j  a v  a 2  s  .c o  m*/
    if (triggersById != null) {
        final List<DelayedMethodCallList> triggersToRedirect = triggersById.remove(idToRedirect);
        if (triggersToRedirect != null) {
            // we redirect triggers to the new list, in two steps, to avoid
            // acquiring
            // locks on two triggers simultaneously, which would be a source
            // of risk of
            // dead locks
            List<DelayedMethodCallList> triggersToRedirectCopy;
            synchronized (triggersToRedirect) {
                triggersToRedirectCopy = new ArrayList<DelayedMethodCallList>(triggersToRedirect);
                triggersToRedirect.clear();
            }
            if (!triggersToRedirectCopy.isEmpty()) {
                final List<DelayedMethodCallList> triggers = getTriggers(application, redirectedId);
                synchronized (triggers) {
                    triggers.addAll(triggersToRedirectCopy);
                }
            }
        }
    }
    if (eventsTimeById != null) {
        eventsTimeById.remove(idToRedirect);
        /*
         * we don't need to merge touch information, since merged behaviors
         * always have the same touch rates
         */
    }
}

From source file:org.wicketstuff.dashboard.web.DashboardSettings.java

License:Apache License

/**
 * Retrieves the instance of settings object.
 *
 * @return settings instance/*  w w w .j a  v a  2 s. c om*/
 */
public static DashboardSettings get() {
    Application application = Application.get();
    DashboardSettings settings = application.getMetaData(KEY);
    if (settings == null) {
        synchronized (application) {
            settings = application.getMetaData(KEY);
            if (settings == null) {
                settings = new DashboardSettings();
                application.setMetaData(KEY, settings);
            }
        }
    }

    return application.getMetaData(KEY);
}

From source file:org.wicketstuff.mergedresources.ResourceMount.java

License:Apache License

/**
 * get {@link ICssCompressor} used by {@link CompressedMergedCssResource}
 * //from  w w w.j  a v a  2 s.  co  m
 * @param application
 */
public static ICssCompressor getCssCompressor(Application application) {
    return application.getMetaData(CSS_COMPRESSOR_KEY);
}

From source file:org.xaloon.wicket.component.inject.j2ee.bm.WeldBeanManagerLocator.java

License:Apache License

private BeanManager getBeanManagerFromApplication(Application application) {
    BeanManager beanManager = null;// w w  w.  j a  v a 2s .c  o  m
    BeanManagerHolder beanManagerHolder = application.getMetaData(BEAN_MANAGER_KEY);
    if (beanManagerHolder == null || beanManagerHolder.getBeanManager() == null) {
        beanManager = locateBeanManagerFromJNDI();
        Application.get().setMetaData(BEAN_MANAGER_KEY, new BeanManagerHolder(beanManager));
    } else {
        beanManager = beanManagerHolder.getBeanManager();
    }
    return beanManager;
}

From source file:ro.fortsoft.wicket.pivot.web.PivotSettings.java

License:Apache License

/**
 * Retrieves the instance of settings object.
 * //from  w w w. ja  v  a  2 s.c o m
 * @return settings instance
 */
public static PivotSettings get() {
    Application application = Application.get();
    PivotSettings settings = application.getMetaData(KEY);
    if (settings == null) {
        synchronized (application) {
            settings = application.getMetaData(KEY);
            if (settings == null) {
                settings = new PivotSettings();
                application.setMetaData(KEY, settings);
            }
        }
    }

    return application.getMetaData(KEY);
}