That means, are we going to consider the failures in the above abstract methods as *unrecoverable* by throwing RuntimeException?
On Tue, Dec 8, 2015 at 3:54 PM, Afkham Azeez <[email protected]> wrote: > Change the code as follows: > > void stopTransport() { <- one of the template methods > stop(); <- abstract method is called > if (state.equals(State.STARTED)) { > state = State.STOPPED; <- state is changed without knowing > the status of stop() call > } else { > throw new IllegalStateException("Cannot stop transport " + id > + ". Current state: " + state); > } > > } > > From the stop() method above, if something fails, throw a RuntimeException. > > On Tue, Dec 8, 2015 at 3:50 PM, Samiyuru Senarathne <[email protected]> > wrote: > >> Hi, >> >> CarbonTransport [1] class in carbon-kernel implements template pattern >> and it has the following abstract methods. >> >> - protected abstract void start(); >> - protected abstract void stop(); >> - protected abstract void beginMaintenance(); >> - protected abstract void endMaintenance(); >> >> These abstract methods should be implemented by any class that implements >> a carbon transport. (For example NettyListener [2] does this). These >> abstract methods are called by the template methods of CarbonTransport >> class. These template methods maintain the state of the carbon transport as >> shown in the following code block. >> >> void stopTransport() { <- one of the template methods >> if (state.equals(State.STARTED)) { >> state = State.STOPPED; <- state is changed without knowing >> the status of stop() call >> } else { >> throw new IllegalStateException("Cannot stop transport " + id >> + ". Current state: " + state); >> } >> stop(); <- abstract method is called >> } >> >> As shown in the above code block CarbonTransport's template functions >> change the state of the transport without knowing the actual state of the >> transport after invoking the abstract function (assuming the abstract >> method call succeeded). >> >> IMO this behaviour can produce invalid states when the operations of the >> abstract method implementations do not complete as expected. IMO in order >> to fix this we can introduce an exception type to the abstract method's >> signature for the implementations to notify any failure or add a state >> return to the signature. >> >> - protected abstract void start() throws CarbonTransportException; >> - protected abstract void stop() throws CarbonTransportException; >> - protected abstract void beginMaintenance() >> throws CarbonTransportException; >> - protected abstract void endMaintenance() >> throws CarbonTransportException; >> >> Or >> >> - protected abstract State start(); >> - protected abstract State stop(); >> - protected abstract State beginMaintenance(); >> - protected abstract State endMaintenance(); >> >> >> WDYT? >> >> [1] - >> https://github.com/wso2/carbon-kernel/blob/master/core/src/main/java/org/wso2/carbon/kernel/transports/CarbonTransport.java >> [2] - >> https://github.com/wso2/carbon-transports/blob/master/http/netty/component/src/main/java/org/wso2/carbon/transport/http/netty/listener/NettyListener.java >> >> Thank you. >> >> Best Regards, >> Samiyuru >> >> -- >> Samiyuru Senarathne >> *Software Engineer* >> Mobile : +94 (0) 71 134 6087 >> [email protected] >> > > > > -- > *Afkham Azeez* > Director of Architecture; WSO2, Inc.; http://wso2.com > Member; Apache Software Foundation; http://www.apache.org/ > * <http://www.apache.org/>* > *email: **[email protected]* <[email protected]> > * cell: +94 77 3320919 <%2B94%2077%203320919>blog: * > *http://blog.afkham.org* <http://blog.afkham.org> > *twitter: **http://twitter.com/afkham_azeez* > <http://twitter.com/afkham_azeez> > *linked-in: **http://lk.linkedin.com/in/afkhamazeez > <http://lk.linkedin.com/in/afkhamazeez>* > > *Lean . Enterprise . Middleware* > -- Samiyuru Senarathne *Software Engineer* Mobile : +94 (0) 71 134 6087 [email protected]
_______________________________________________ Architecture mailing list [email protected] https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
