-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBufferFactory.groovy
More file actions
27 lines (23 loc) · 870 Bytes
/
BufferFactory.groovy
File metadata and controls
27 lines (23 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import org.springframework.beans.BeansException
import org.springframework.context.ApplicationContext
import org.springframework.context.ApplicationContextAware
import org.springframework.stereotype.Component
import java.util.function.Supplier
/**
* @author Jonatan Ivanov
*/
@Component
class BufferFactory implements ApplicationContextAware {
private ApplicationContext applicationContext
Buffer createBuffer(BufferProperty bufferProperty) {
return new Buffer(
bufferProperty.name ?: UUID.randomUUID().toString(),
applicationContext.getBean(bufferProperty.supplierName, Supplier.class),
bufferProperty.desiredSize
)
}
@Override
void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext
}
}