this.service = service; classMeta = (ClassMeta<Class<?>>) ClassMeta.classMeta(service.getClass()); addresses.add(Str.add(rootAddress, "/", classMeta.longName())); addresses.add(Str.add(rootAddress, "/", classMeta.longName().toLowerCase())); serviceAddress = Str.camelCaseLower(classMeta.name()); this.name = Str.uncapitalize(classMeta.name()); final Iterable<MethodAccess> methods = classMeta.methods(); final Class<?>[] interfaces = classMeta.cls().getInterfaces(); for (Class<?> interfaceClass : interfaces) { final ClassMeta<?> interfaceMeta = ClassMeta.classMeta(interfaceClass); interfaceMeta.annotation(AnnotationUtils.EVENT_CHANNEL_ANNOTATION_NAME); interfaceMeta.methods().forEach(methodAccess -> {
public DynamicQueueCallbackHandler(Object service) { final ClassMeta<Class<?>> classMeta; this.service = service; //noinspection unchecked classMeta = (ClassMeta<Class<?>>) ClassMeta.classMeta(service.getClass()); queueLimit = classMeta.method("queueLimit"); queueEmpty = classMeta.method("queueEmpty"); queueShutdown = classMeta.method("queueShutdown"); queueIdle = classMeta.method("queueIdle"); queueInit = classMeta.method("queueInit"); queueStartBatch = classMeta.method("queueStartBatch"); }
this.queue = ClassMeta.classMeta(queueClass).noArgConstructor().create(); } else { final ClassMeta<? extends BlockingQueue> classMeta = ClassMeta.classMeta(queueClass); if (queueClass != LinkedTransferQueue.class) { if (debug) logger.debug("Not a LinkedTransfer queue"); final ConstructorAccess<Object> constructor = classMeta.declaredConstructor(int.class); final ConstructorAccess<? extends BlockingQueue> constructorAccess = classMeta.noArgConstructor();
private void registerReflectionAndJsonParser() { try { final Class<?> boonFactory = Class.forName("io.advantageous.qbit.boon.spi.RegisterBoonWithQBit"); ClassMeta.classMeta(boonFactory).invokeStatic("registerBoonWithQBit"); } catch (ClassNotFoundException e) { throw new IllegalStateException("Could not find reflection lib or JSON parser"); } }
private <T> void validateInterface(Class<T> serviceInterface) { if (!serviceInterface.isInterface()) { throw new IllegalStateException("Service Interface must be an interface " + serviceInterface.getName()); } final ClassMeta<T> classMeta = ClassMeta.classMeta(serviceInterface); final Method[] declaredMethods = classMeta.cls().getDeclaredMethods(); for (Method m : declaredMethods) { if (!(m.getReturnType() == void.class || Promise.class.isAssignableFrom(m.getReturnType()))) { throw new IllegalStateException("Async interface can only return void or a Promise " + serviceInterface.getName()); } } }
private static boolean hasQueueCallbackAnnotations(Object service) { @SuppressWarnings("unchecked") ClassMeta<Class<?>> classMeta = (ClassMeta<Class<?>>) ClassMeta.classMeta(service.getClass()); final Iterable<MethodAccess> methods = classMeta.methods(); for (MethodAccess methodAccess : methods) { if (methodAccess.hasAnnotation(QUEUE_CALLBACK_ANNOTATION_NAME)) { return true; } } return false; } }
name, listener, serviceQueue); final ClassMeta<?> listenerClassMeta = ClassMeta.classMeta(listener.getClass()); final Iterable<MethodAccess> listenerMethods = listenerClassMeta.methods(); final Class<?>[] interfacesFromListener = listenerClassMeta.cls().getInterfaces(); final ClassMeta<?> metaFromListenerInterface = classMeta(interfaceClass); .annotation(AnnotationUtils.EVENT_CHANNEL_ANNOTATION_NAME); if (eventChannelAnnotation == null) { continue; final Iterable<MethodAccess> interfaceMethods = metaFromListenerInterface.methods();
private <T> Map<String, String> createMethodToChannelMap(final String channelPrefix, final Class<T> eventBusProxyInterface) { final Map<String, String> methodToChannelMap = new ConcurrentHashMap<>(20); final ClassMeta<T> classMeta = classMeta(eventBusProxyInterface); final AnnotationData classAnnotation = classMeta.annotation(AnnotationUtils.EVENT_CHANNEL_ANNOTATION_NAME); final String classEventBusName = AnnotationUtils.getClassEventChannelName(classMeta, classAnnotation); classMeta.methods().forEach(methodAccess -> { AnnotationData methodAnnotation = methodAccess.annotation(AnnotationUtils.EVENT_CHANNEL_ANNOTATION_NAME); String methodEventBusName = methodAnnotation != null && methodAnnotation.getValues().get("value") != null ? methodAnnotation.getValues().get("value").toString() : null; if (Str.isEmpty(methodEventBusName)) { methodEventBusName = methodAccess.name(); } final String channelName = createChannelName(channelPrefix, classEventBusName, methodEventBusName); methodToChannelMap.put(methodAccess.method().toString(), channelName); }); return methodToChannelMap; }
public ServiceBuilder setServiceObject(final Object serviceObject) { if (serviceObject == null) { throw new IllegalArgumentException("ServiceBuilder setServiceObject:: serviceObject cant be null"); } ClassMeta<?> classMeta = ClassMeta.classMeta(serviceObject.getClass()); Iterable<MethodAccess> methods = classMeta.methods(); Set<String> methodNames = new HashSet<>(); for (MethodAccess methodAccess : methods) { if (methodAccess.isPrivate() || methodAccess.method().getDeclaringClass().getName().contains("$$EnhancerByGuice$$")) { continue; } if (methodNames.contains(methodAccess.name())) { logger.error("QBit does not support method overloading methods in Service Queues" + " problem name " + methodAccess.name() + " is overloaded " + methodNames + " from class " + classMeta.longName()); } else { methodNames.add(methodAccess.name()); } } this.serviceObject = serviceObject; return this; }
if (definitionMap.containsKey("jsend-array-" + classMeta.name())) { return; definitionMap.put("jsend-array-" + classMeta.name(), null); Schema schema = mappings.get(classMeta.cls()); definitionMap.put("jsend-array-" + classMeta.name(), definition); logger.warn("Unable to add class " + classMeta.longName(), ex);
public static <V, WRAP> List<WRAP> wrap(Class<WRAP> wrapper, Collection<V> collection ) { if (collection.size()==0) { return Collections.EMPTY_LIST; } List<WRAP> list = new ArrayList<>( collection.size () ); ClassMeta<WRAP> cls = ClassMeta.classMeta(wrapper); ConstructorAccess<WRAP> declaredConstructor = cls.declaredConstructor(collection.iterator().next().getClass()); for (V v : collection) { WRAP wrap = declaredConstructor.create ( v ); list.add ( wrap ); } return list; }
}else { Class currentClass = ClassMeta.cls(item);
/** * Get fields from object or Map. * Allows maps to act like they have fields. * * @param object object * @return names/fields mapping */ public static Map<String, FieldAccess> getFieldsFromObject( Object object ) { try { Map<String, FieldAccess> fields; if ( object instanceof Map ) { fields = getFieldsFromMap( ( Map<String, Object> ) object ); } else { fields = getPropertyFieldAccessMap( object.getClass() ); } return fields; } catch (Exception ex) { Exceptions.requireNonNull(object, "Item cannot be null"); return handle(Map.class, ex, "Unable to get fields from object", className(object)); } }
public static <T> T newInstance( Class<T> clazz ) { T newInstance = null; ClassMeta <T> cls = ClassMeta.classMeta(clazz); try { /* See if there is a no arg constructor. */ ConstructorAccess<T> declaredConstructor = cls.noArgConstructor(); if (declaredConstructor !=null ) { /* If there was a no argument constructor, then use it. */ newInstance = declaredConstructor.create(); } else { if ( _useUnsafe ) { newInstance = ( T ) getUnsafe().allocateInstance( clazz ); } else { Exceptions.die (Str.sputs(clazz.getName(), "does not have a no arg constructor and unsafe is not turned on")); } } } catch ( Exception ex ) { try { if ( _useUnsafe ) { newInstance = ( T ) getUnsafe().allocateInstance( clazz ); return newInstance; //we handled it. } } catch ( Exception ex2 ) { handle( ex2 ); } handle( ex ); } return newInstance; }
public static String readServiceName(Object annotated) { final ClassMeta classMeta = ClassMeta.classMeta(annotated.getClass()); final String name = readServiceName(classMeta); if (name == null || name.isEmpty()) { return annotated.getClass().getSimpleName(); } else { return name; } }
private void addClass(final ClassMeta<?> classMeta) { try { if (definitionMap.containsKey(classMeta.name())) { return; } definitionMap.put(classMeta.name(), null); final DefinitionBuilder definitionBuilder = new DefinitionBuilder(); final String description = getDescription(classMeta); definitionBuilder.setDescription(description); final Map<String, FieldAccess> fieldAccessMap = classMeta.fieldMap(); fieldAccessMap.entrySet().forEach(fieldAccessEntry -> { final FieldAccess fieldAccess = fieldAccessEntry.getValue(); if (fieldAccess.ignore() || fieldAccess.isStatic()) { return; } definitionBuilder.addProperty(fieldAccess.name(), convertFieldToSchema(fieldAccess)); }); final Definition definition = definitionBuilder.build(); definitionMap.put(classMeta.name(), definition); } catch (Exception ex) { logger.warn("Unable to add class " + classMeta.longName(), ex); } }
private Response<Object> invokeByName(MethodCall<Object> methodCall) { final MethodAccess method = classMeta.method(methodCall.name()); if (method != null) { return mapArgsAsyncHandlersAndInvoke(methodCall, method); } else { if (methodCall.name().equals("toString")) { return ResponseImpl.response( methodCall.id(), methodCall.timestamp(), methodCall.address(), methodCall.returnAddress(), sputs("Method Call toString was called", methodCall.objectName(), methodCall.name(), methodCall.address()), methodCall, false); } else { return ResponseImpl.response( methodCall.id(), methodCall.timestamp(), methodCall.address(), methodCall.returnAddress(), new Exception("Unable to find method " + methodCall.name()), methodCall, true); } } }