1<?php 2/** 3 * Interface for salvageable services. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 * http://www.gnu.org/copyleft/gpl.html 19 * 20 * @file 21 */ 22 23namespace Wikimedia\Services; 24 25/** 26 * SalvageableService defines an interface for services that are able to salvage state from a 27 * previous instance of the same class. The intent is to allow new service instances to re-use 28 * resources that would be expensive to re-create, such as cached data or network connections. 29 * 30 * @note There is no expectation that services will be destroyed when the process (or web request) 31 * terminates. 32 */ 33interface SalvageableService { 34 35 /** 36 * Re-uses state from $other. $other must not be used after being passed to salvage(), 37 * and should be considered to be destroyed. 38 * 39 * @note Implementations are responsible for determining what parts of $other can be re-used 40 * safely. In particular, implementations should check that the relevant configuration of 41 * $other is the same as in $this before re-using resources from $other. 42 * 43 * @note Implementations must take care to detach any re-used resources from the original 44 * service instance. If $other is destroyed later, resources that are now used by the 45 * new service instance must not be affected. 46 * 47 * @note If $other is a DestructibleService, implementations should make sure that $other 48 * is in destroyed state after salvage finished. This may be done by calling $other->destroy() 49 * after carefully detaching all relevant resources. 50 * 51 * @param SalvageableService $other The object to salvage state from. $other must have the 52 * exact same type as $this. 53 */ 54 public function salvage( SalvageableService $other ); 55 56} 57