001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.http2; 018 019import org.apache.wicket.Application; 020import org.apache.wicket.MetaDataKey; 021import org.apache.wicket.http2.markup.head.NoopPushBuilder; 022import org.apache.wicket.http2.markup.head.PushBuilder; 023import org.apache.wicket.util.lang.Args; 024 025/** 026 * The http2 settings used to get the vendor specific push builder API 027 * 028 * @author Martin Grigorov 029 */ 030public class Http2Settings 031{ 032 /** 033 * The meta data key of the http2 settings 034 */ 035 private static final MetaDataKey<Http2Settings> KEY = new MetaDataKey<>() 036 { 037 private static final long serialVersionUID = 1L; 038 }; 039 040 /** 041 * Holds this Http2Settings in the Application's meta data. This way wicket-core module doesn't 042 * have reference to wicket-http2-core 043 */ 044 public static final class Holder 045 { 046 /** 047 * Gets the http2 settings from the given application 048 * 049 * @param application 050 * the application to get the meta data from 051 * @return the http2 settings 052 */ 053 public static Http2Settings get(Application application) 054 { 055 Http2Settings settings = application.getMetaData(KEY); 056 if (settings == null) 057 { 058 synchronized (application) 059 { 060 if (settings == null) 061 { 062 settings = new Http2Settings(); 063 set(application, settings); 064 } 065 } 066 } 067 return settings; 068 } 069 070 /** 071 * Sets the given http2 settings to the given application 072 * 073 * @param application 074 * the application to set the meta data key to 075 * @param settings 076 * the http2 settings to be set to the application 077 */ 078 public static void set(Application application, Http2Settings settings) 079 { 080 application.setMetaData(KEY, settings); 081 } 082 } 083 084 private PushBuilder pushBuilder = NoopPushBuilder.INSTANCE; 085 086 /** 087 * Sets the push builder that has been initialized 088 * 089 * @param pushBuilder 090 * the push builder to be used after the initialization 091 * @return the push builder 092 */ 093 public Http2Settings setPushBuilder(PushBuilder pushBuilder) 094 { 095 this.pushBuilder = Args.notNull(pushBuilder, "pushBuilder"); 096 return this; 097 } 098 099 /** 100 * Gets the push builder which has been initialized 101 * 102 * @return the push builder 103 */ 104 public PushBuilder getPushBuilder() 105 { 106 return pushBuilder; 107 } 108}