Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      It's more a question than 'issue'.

      We have several (actually quite a few) Providers.

      I wonder how could we centralize those exceptions and log them.

        Activity

        Hide
        jwells added a comment -

        So... what is wrong with ErrorService:

        https://hk2.java.net/2.4.0-b06/apidocs/org/glassfish/hk2/api/ErrorService.html

        There are error types:

        https://hk2.java.net/2.4.0-b06/apidocs/org/glassfish/hk2/api/ErrorType.html

        SERVICE_CREATION_FAILURE
        SERVICE_DESTRUCTION_FAILURE

        I think that should be all you need!

        Show
        jwells added a comment - So... what is wrong with ErrorService: https://hk2.java.net/2.4.0-b06/apidocs/org/glassfish/hk2/api/ErrorService.html There are error types: https://hk2.java.net/2.4.0-b06/apidocs/org/glassfish/hk2/api/ErrorType.html SERVICE_CREATION_FAILURE SERVICE_DESTRUCTION_FAILURE I think that should be all you need!
        Hide
        jwells added a comment -

        I think the existing ErrorService would work properly in this case

        Show
        jwells added a comment - I think the existing ErrorService would work properly in this case
        Hide
        saden added a comment -

        I wasn't aware of the ErrorService feature. It's a great feature that will enable us to get error notification but won't allow us to "handle" the error. Ideally we would like to tell HK2 to let us handle the error rather than propagating it.

        Show
        saden added a comment - I wasn't aware of the ErrorService feature. It's a great feature that will enable us to get error notification but won't allow us to "handle" the error. Ideally we would like to tell HK2 to let us handle the error rather than propagating it.
        Hide
        jwells added a comment -

        How would you want to be able to "handle" these sort of errors? Would you, like, add in a descriptor, or want to return some object from creation? What would this error handler actually want to be able to do?

        Show
        jwells added a comment - How would you want to be able to "handle" these sort of errors? Would you, like, add in a descriptor, or want to return some object from creation? What would this error handler actually want to be able to do?
        Hide
        saden added a comment -

        Good question. The more I think about it the more I realize that what I really want to do is have the ability to turn off exception propagation if the injectee is optional and use ErrorService for logging and notification purpose.

        Even though the provider throws an exception AccountService should still get created because Account is optional.

        public class Account() {
            ...
        }
        
        @Service
        public class AccountProvider implements Factory<Account> {
        
            @Override
            public String provide() {
                throw new UnsupportedOperationException("Not supported yet.");
            }
        
            @Override
            public void dispose(Account instance) {
            }
        
        }
        
        @Service
        public class AccountService {
        
            private final Account account;
        
            @Inject
            AccountService(@Optional Account account) {
                this.account = account;
            }
        
          public void doSomething() {
            ....
          }
        
        }
        
        Show
        saden added a comment - Good question. The more I think about it the more I realize that what I really want to do is have the ability to turn off exception propagation if the injectee is optional and use ErrorService for logging and notification purpose. Even though the provider throws an exception AccountService should still get created because Account is optional. public class Account() { ... } @Service public class AccountProvider implements Factory<Account> { @Override public String provide() { throw new UnsupportedOperationException( "Not supported yet." ); } @Override public void dispose(Account instance) { } } @Service public class AccountService { private final Account account; @Inject AccountService(@Optional Account account) { this .account = account; } public void doSomething() { .... } }

          People

          • Assignee:
            jwells
            Reporter:
            mingtaozhang
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: