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.page;
018
019import java.time.Duration;
020
021/**
022 * An exception that is being thrown when a second thread attempts to get
023 * the lock on a page instance that is currently locked by another thread and it cannot
024 * do that for some specified {@link org.apache.wicket.settings.RequestCycleSettings#getTimeout() duration}
025 *
026 * @see org.apache.wicket.settings.RequestCycleSettings#setTimeout(Duration)
027 * @see org.apache.wicket.settings.ExceptionSettings#setThreadDumpStrategy(org.apache.wicket.settings.ExceptionSettings.ThreadDumpStrategy)
028 */
029public class CouldNotLockPageException extends RuntimeException
030{
031        private static final long serialVersionUID = 1L;
032
033        private final int page;
034        private final Duration timeout;
035        private final String threadName;
036
037        /**
038         * Construct.
039         * 
040         * @param page
041         *      the id of the page instance which is already locked
042         * @param threadName
043         *      the name of the thread that attempts to acquire the lock on the page
044         * @param timeout
045         *      the duration that the second thread waited for the lock
046         */
047        public CouldNotLockPageException(int page, String threadName, Duration timeout)
048        {
049                super("Could not lock page " + page + ". Attempt lasted " + timeout);
050                this.page = page;
051                this.timeout = timeout;
052                this.threadName = threadName;
053        }
054
055        /**
056         * @return page
057         */
058        public int getPage()
059        {
060                return page;
061        }
062
063        /**
064         * @return timeout
065         */
066        public Duration getTimeout()
067        {
068                return timeout;
069        }
070
071        /**
072         * @return threadName
073         */
074        public String getThreadName()
075        {
076                return threadName;
077        }
078}