Skip to content

Instantly share code, notes, and snippets.

@AdamBien
Last active June 6, 2016 13:55
Show Gist options
  • Save AdamBien/5e784dcdacf08e6bde0d7e207efb5ba5 to your computer and use it in GitHub Desktop.
Save AdamBien/5e784dcdacf08e6bde0d7e207efb5ba5 to your computer and use it in GitHub Desktop.
27thAirhacksQ&A.md
@retepnemsi
Copy link

retepnemsi commented Jun 3, 2016

Hi Adam,

As suggested in your blog post BEANS WITH BOTH VIEWS (@Local AND @Remote) - AN ANTI PATTERN? I have a @Local interface that extends a @Remote interface and my session bean implements the local interface. An objection have been raised against this pattern, suggesting that calling a method defined in the remote interface through the local interface still occur the remote call penalty. Is this so, and how can I prove the opposite if not?

The suggested solution was to have a common interface for the methods that are shared loacal and remote and then extend both @Local and @Remote interfaces from the common one and the sessionbean impkements both local and remote.

I had a look at the generated code but both local and remote calls looks the same to me, I suppose the invokevirtual operation does some magic that I don't see.

Thanks for the show, the On demand workshops and hope to see you at JavaOne.

@Andy-Voigt
Copy link

Andy-Voigt commented Jun 5, 2016

Hello Adam,

i've written a property resolver. The resolver should read a application.properties file and produce the values. It works but only if i deploy the application twice. The file is never found if i simply deploy the application over the Web-Interface. My application server is the new Wildfly 10. Its seems that the file is only discovered the second time in the classpath. I can simply reproduced if i deploy the war over the ide and stop/start the server. Any ideas why this happens?

@Singleton
public class PropertyResolver {

    @Inject
    private Logger logger;

    private final String propertiesFileName = "application.properties";

    private Map<String, Object> properties = new HashMap<>();

    @PostConstruct
    private void init() {
        Properties p = new Properties();
        try {
            p.load(this.getClass().getClassLoader().getResourceAsStream(propertiesFileName));
        } catch (Exception e) {
            logger.log(Level.SEVERE,  "The file " + propertiesFileName + " could not be found in classpath. The exception wars:\n " + e);
        }
        properties.putAll((Map) p);
        properties.putAll(System.getenv());
    }

    @Lock(LockType.READ)
    public String getValue(String key) {
        Object value = properties.get(key);
        return (value != null) ? String.valueOf(value) : null;
    }
}
public class PropertyValueProducer {

    @Inject
    private PropertyResolver resolver;

    @Produces
    @Property
    public String getStringConfigValue(InjectionPoint ip) {
        String fqn = ip.getMember().getDeclaringClass().getName() + "." + ip.getMember().getName();
        String key = ip.getAnnotated().getAnnotation(Property.class).value();
        boolean isKeyDefined = !key.trim().isEmpty();
        boolean valueRequired = ip.getAnnotated().getAnnotation(Property.class).required();
        if (isKeyDefined) {
            return resolver.getValue(key);
        }

        String value = resolver.getValue(fqn);
        if (value == null) {
            key = ip.getMember().getName();
            value = resolver.getValue(key);
        }

        if (value == null && valueRequired) {
            throw new IllegalStateException("No value defined for field: " + fqn + " but field was marked as required.");
        }
        return value;
    }


    @Produces
    @Property
    public Integer getIntegerConfigValue(InjectionPoint ip) {
        String value = getStringConfigValue(ip);
        return (value != null) ? Integer.valueOf(value) : null;
    }

    @Produces
    @Property
    public Double getDoubleConfigValue(InjectionPoint ip) {
        String value = getStringConfigValue(ip);
        return (value != null) ? Double.valueOf(value) : null;
    }
}
@Qualifier
@Retention(RUNTIME)
@Target({ TYPE, METHOD, FIELD, PARAMETER })
public @interface Property {

    @Nonbinding
    String value() default "";

    @Nonbinding
    boolean required() default true;
}

@glitchcube
Copy link

Hi, Adam!

In a video you made in 2013, you explain how you structure a JavaEE project. https://www.youtube.com/watch?v=grJC6RFiB58 (Structuring Java EE 7 Applications) using the BCE(boundary, control, entity) pattern.

As I read in http://epf.eclipse.org/wikis/openuppt/openup_basic/guidances/concepts/entity_control_boundary_pattern,_uF-QYEAhEdq_UJTvM1DM2Q.html the boundary should only communicate with the control.

Can/Should the boundary communicate directly with the entity, as you are doing in this video?
public void savePost(String message) { pv.isValid(message); em.merge(new Post(message)); }

Added note: I just watch your video on Microservices and loved it. Keep up with the good work you are doing, Adam.

/Java EE enthusiast from Norway

@linfey
Copy link

linfey commented Jun 6, 2016

Hello Adam,
what are your thoughts on the Oracle Application Development Framework.
It's advertised as a Java EE Framework but speaking frankly I fail to see the Java EE part beside the fact you need a welogic server to run any ADF application.
Does ADF play a role in your projects?

@robertBrem
Copy link

Hy Adam

Your vimeo workshops are great!
Do you have plans to make more? For example: Java EE 7 Architectures?

Greets
Rob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment