|
| 1 | +package com.github.lancearlaus.akka.spring; |
| 2 | + |
| 3 | +import org.springframework.beans.factory.annotation.Autowire; |
| 4 | +import org.springframework.beans.factory.config.ConfigurableBeanFactory; |
| 5 | +import org.springframework.beans.factory.support.AbstractBeanDefinition; |
| 6 | +import org.springframework.context.annotation.Bean; |
| 7 | +import org.springframework.context.annotation.Scope; |
| 8 | + |
| 9 | +import java.lang.annotation.ElementType; |
| 10 | +import java.lang.annotation.Retention; |
| 11 | +import java.lang.annotation.RetentionPolicy; |
| 12 | +import java.lang.annotation.Target; |
| 13 | + |
| 14 | +/** |
| 15 | + * Annotate actor beans (not actor references!) within a Spring configuration. |
| 16 | + * |
| 17 | + * This annotation SHOULD only be required for Actor-based classes used from third-party |
| 18 | + * libraries, etc. Please use the {@code ActorComponent} annotation to annotate your |
| 19 | + * classes instead if you're creating your own actors for use with Spring. |
| 20 | + * |
| 21 | + * @see com.github.lancearlaus.akka.spring.ActorComponent |
| 22 | + */ |
| 23 | +@Bean |
| 24 | +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) |
| 25 | +@Target({ElementType.METHOD}) |
| 26 | +@Retention(RetentionPolicy.RUNTIME) |
| 27 | +public @interface ActorBean { |
| 28 | + /** |
| 29 | + * The name of this bean, or if plural, aliases for this bean. If left unspecified |
| 30 | + * the name of the bean is the name of the annotated method. If specified, the method |
| 31 | + * name is ignored. |
| 32 | + */ |
| 33 | + String[] name() default {}; |
| 34 | + |
| 35 | + /** |
| 36 | + * Are dependencies to be injected via convention-based autowiring by name or type? |
| 37 | + */ |
| 38 | + Autowire autowire() default Autowire.NO; |
| 39 | + |
| 40 | + /** |
| 41 | + * The optional name of a method to call on the bean instance during initialization. |
| 42 | + * Not commonly used, given that the method may be called programmatically directly |
| 43 | + * within the body of a Bean-annotated method. |
| 44 | + * <p>The default value is {@code ""}, indicating no init method to be called. |
| 45 | + */ |
| 46 | + String initMethod() default ""; |
| 47 | + |
| 48 | + /** |
| 49 | + * The optional name of a method to call on the bean instance upon closing the |
| 50 | + * application context, for example a {@code close()} method on a JDBC |
| 51 | + * {@code DataSource} implementation, or a Hibernate {@code SessionFactory} object. |
| 52 | + * The method must have no arguments but may throw any exception. |
| 53 | + * <p>As a convenience to the user, the container will attempt to infer a destroy |
| 54 | + * method against an object returned from the {@code @Bean} method. For example, given |
| 55 | + * an {@code @Bean} method returning an Apache Commons DBCP {@code BasicDataSource}, |
| 56 | + * the container will notice the {@code close()} method available on that object and |
| 57 | + * automatically register it as the {@code destroyMethod}. This 'destroy method |
| 58 | + * inference' is currently limited to detecting only public, no-arg methods named |
| 59 | + * 'close' or 'shutdown'. The method may be declared at any level of the inheritance |
| 60 | + * hierarchy and will be detected regardless of the return type of the {@code @Bean} |
| 61 | + * method (i.e., detection occurs reflectively against the bean instance itself at |
| 62 | + * creation time). |
| 63 | + * <p>To disable destroy method inference for a particular {@code @Bean}, specify an |
| 64 | + * empty string as the value, e.g. {@code @Bean(destroyMethod="")}. Note that the |
| 65 | + * {@link org.springframework.beans.factory.DisposableBean} and the |
| 66 | + * {@link java.io.Closeable}/{@link java.lang.AutoCloseable} interfaces will |
| 67 | + * nevertheless get detected and the corresponding destroy/close method invoked. |
| 68 | + * <p>Note: Only invoked on beans whose lifecycle is under the full control of the |
| 69 | + * factory, which is always the case for singletons but not guaranteed for any |
| 70 | + * other scope. |
| 71 | + * @see org.springframework.context.ConfigurableApplicationContext#close() |
| 72 | + */ |
| 73 | + String destroyMethod() default AbstractBeanDefinition.INFER_METHOD; |
| 74 | +} |
0 commit comments