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 */ 017 package org.apache.xbean.kernel; 018 019 import java.util.Set; 020 021 /** 022 * This class holds information about a service event. 023 * 024 * @author Dain Sundstrom 025 * @version $Id$ 026 * @since 2.0 027 */ 028 public class ServiceEvent { 029 private final long eventId; 030 private final Kernel kernel; 031 private final ServiceName serviceName; 032 private final ServiceFactory serviceFactory; 033 private final ClassLoader classLoader; 034 private final Object service; 035 private final Throwable cause; 036 private final Set unsatisfiedConditions; 037 038 /** 039 * Creates a service event. 040 * 041 * @param eventId the sequence number for this event 042 * @param kernel the kernel in which the service is registered 043 * @param serviceName the name of the service 044 * @param serviceFactory the factory for the service 045 * @param classLoader the class loader for the service 046 * @param service the service instance if it exists 047 * @param cause the exception that caused the event if this is an exception event 048 * @param unsatisfiedConditions the unsatified conditions that caused the event if this is a waiting event 049 */ 050 public ServiceEvent(long eventId, Kernel kernel, ServiceName serviceName, ServiceFactory serviceFactory, ClassLoader classLoader, Object service, Throwable cause, Set unsatisfiedConditions) { 051 if (kernel == null) throw new NullPointerException("kernel is null"); 052 if (serviceName == null) throw new NullPointerException("name is null"); 053 if (serviceFactory == null) throw new NullPointerException("serviceFactory is null"); 054 if (classLoader == null) throw new NullPointerException("classLoader is null"); 055 if (unsatisfiedConditions != null && cause != null) throw new IllegalArgumentException("Either unsatisfiedConditions or cause must be null"); 056 if (cause != null && service != null) throw new IllegalArgumentException("A ServiceEvent can not carry both a cause and a service"); 057 this.eventId = eventId; 058 this.kernel = kernel; 059 this.serviceName = serviceName; 060 this.serviceFactory = serviceFactory; 061 this.classLoader = classLoader; 062 this.service = service; 063 this.cause = cause; 064 this.unsatisfiedConditions = unsatisfiedConditions; 065 } 066 067 /** 068 * Gets the sequence number for this event. A service gaurentees that events will occur in increasing order with out 069 * skipping any numbers. 070 * 071 * @return the sequence number for this event 072 */ 073 public long getEventId() { 074 return eventId; 075 } 076 077 /** 078 * Gets the kernel in which the service is registered. 079 * 080 * @return the kernel in which the servce is registerd 081 */ 082 public Kernel getKernel() { 083 return kernel; 084 } 085 086 /** 087 * Gets the name of the service. 088 * 089 * @return the name of the service 090 */ 091 public ServiceName getServiceName() { 092 return serviceName; 093 } 094 095 /** 096 * Gets the service factory for the service. 097 * 098 * @return the service factory for the service 099 */ 100 public ServiceFactory getServiceFactory() { 101 return serviceFactory; 102 } 103 104 /** 105 * Gets the class loader for the service. 106 * 107 * @return the class loader for the service 108 */ 109 public ClassLoader getClassLoader() { 110 return classLoader; 111 } 112 113 /** 114 * Gets the service instance or null if the service doesn't exist. 115 * 116 * @return the service instance 117 */ 118 public Object getService() { 119 return service; 120 } 121 122 /** 123 * Gets the error that was thrown during startup or shutdown. This is available only in error events. 124 * 125 * @return the error 126 */ 127 public Throwable getCause() { 128 return cause; 129 } 130 131 /** 132 * Gets the unsatified dependencies that cause the service to wait. This is available only in waiting events. 133 * 134 * @return the unsatified dependencies that cause the service to wait 135 */ 136 public Set getUnsatisfiedConditions() { 137 return unsatisfiedConditions; 138 } 139 }