Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

Vish Shukla

Ranch Hand
+ Follow
since Oct 12, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vish Shukla

Hi Azuki,

Use appropriate synchronization in below sequence of preference
1. Reentrant read-write lock
2. Synchronized block
3. Synchronized method

Also, you can try actor based concurrency. This is a kind of pattern where you dedicate ONLY ONE thread to do mutations on a resource.

To avoid race conditions, the answer is religious code review, multi-threaded unit tests. There is no short cut.

The best thing would be to create side-effect free and stateless functions, use immutables as much as possible. But that is not possible always. So use java.util.concurrent.atomic, concurrent data structures like prefer ConcurrentHashMap instead of HashMap.

The best resource for concurrency is JCIP. You can also get some more details on above explanation here.
Jon,

What is missing in this design is some proper abstractions and encapsulation of some behaviors.

The design can be broken down into the interfaces and classes as shown this class diagram.



Here are few points to back this design.

Data - What if you need to compare datasets got from webservice or 2 files instead of directories? Abstract the data.
DataLoader - Different strategy to load the data in future? Encapsulate data loading concern. Single responsibility. Same applies to DataTester.
DataLoaderImpl - Constructor takes config params. May be using injector. You will get rid of changing parameters by this. The only change would be in this DataLoaderImpl class.
ValueComparator - Uses Loader and Tester - configured in the constructor - and performs comparison logic. If you feel, it may also be good idea to move comparison logic to another abstraction and encapsulate it(if it can vary). In that case, you will have one class which only works as a facade to provide high level functionality of comparing two directories.

From your Main, construct all dependencies required by ValuComparator or use IOC container to manage wirings.

You can read some practical examples of abstraction and encapsulation at FearlessDeveloper.
6 years ago
Adding to what Winston mentioned, what Abstraction enables you to do is, the capability to use the same concrete class in completely unrelated clients. In other words, it allows client to see his perspective. Car is a concrete class. But if I am the vehicle tracking application, I am only concerned with its x & y co-ordinates - I can have an interface with only those methods. If I am a driver of the car, my abstraction will have methods like start, stop, accelerate and so on. Check out the article on abstraction at FearlessDeveloper.

Where as Encapsulation allows the class to completely control how it should behave - by controlling the way its data access & mutation. Car class may have data - speed. Client of car class cannot change speed of car from +100 to -100 directly. You need to change gears to get the speed down, break, take reverse and there will be limit on the max speed in reverse. This can be achieved using Encapsulation. You hide speed. You provide accelerator and break. Check out the article on Encapsulation.
6 years ago
Encapsulation has to do with hiding data, give it a name(private data members in a class - Car) and binding behavior methods(start, stop, accelerate) with it. These behavior methods will mutate or provide access to those data variables.

Abstraction provides perspective of the client in abstract terms. As a concept or an idea. This generalization allows clients to ONLY focus on What they are concerned with. Car is concrete entity where as Drivable, Trackable(which has position and can be tracked down) can be abstraction for Car for different clients.

You can check some real life examples of Abstraction and Encapsulation here.
6 years ago
Encapsulation has to do with hiding data, give it a name(private data members in a class - Car) and binding behavior methods(start, stop, accelerate) with it. These behavior methods will mutate or provide access to those data variables.

Abstraction provides perspective of the client in abstract terms. As a concept or an idea. This generalization allows clients to ONLY focus on What they are concerned with. Car is concrete entity where as Drivable, Trackable(which has position and can be tracked down) can be abstraction for Car for different clients.

You can check some real life examples of Abstraction and Encapsulation here.
6 years ago
So what should be the ideal way one could start of the project, in BDD way? When you are not even aware about what all components your system would have, what should be the very first step to derive the high level design & even component level design out of the requirements.
7 years ago
BDD looks like a very good tool for Requirement elicitation and Requirement specification. Does BDD encourage involvement of business analyst or customer or even BDD tests to be developed only by business analysts, if you have such dedicated roles in the company?
7 years ago
John, it would be good to hear your words on this.
7 years ago
BDD can be considered as a specialized case of TDD.

I am also learner of TDD & BDD. However, would like to share my understanding on this. Focus of BDD is more on the end to end behavior of the component or the system. Where in you involve business analyst/customer and developers. Hence, the language used in BDD is also more like natural language.

On the other end, focus of TDD is behavior of the unit under development, and general practice is to mock out the dependencies of the component. Which is more relevant for developers. The implication which I have experienced because of mocking is that one needs to know some level of implementation details of the component like dependencies of the component, what methods will be called in the dependent components (so you can mock out behavior of those methods). Which, in case of BDD, customer or business analyst doesn't really need to care about.

One could argue that people also write tests for components without mocking the dependencies when using TDD. My say on this would be if that component makes sense to business and covers business use-cases and was developed with "outside-in" approach, then it is indeed BDD.

Thanks & Regards,
Vishal Shukla
7 years ago
Hi all,

I am new to MongoDB. I am preparing an example for learning and seems like when working with bi-directional relationship with Spring Data & DBRef, MongoMappingConverter gets into end-less cycle and keeps reading the association again and again.

I wonder if it is the rare scenario(quite commong in ORMs though), couldn't get any help on this. One option could be writing custom converter and ignoring anyone side of relation, but that will turn my in-memory bean into a stale state.

Please share ideas on this.

Thanks.
7 years ago
Hi all,

I need to call Sharepoint 2010 webservice from Java code & pass NTLM credentials which will be looked up in active directory server by sharepoint. I am have generated Axis2 stubs to achieve this, but when I am trying to use NTLM authenticator but it goes in infinite loop and server keeps returning 401 error.

I have googled enough to get NTLM working with Axis2 but, couldn't get anything concrete that works properly. Is it possible to use NTLM authenticator with Axis2?

Any help is appreciated. I am open to use any non-Axis stubs also, goal is to use NTLM or windows credential SPNEGO token to call sharepoint webservice.

Thanks in advance.

9 years ago
Hi all,

I have 2 modularized spring projects, packaged as jar files, containing their own applicationContext.xml. I need to reference bean declarations of these xml in war file.

webapp.war
- WEB-INF
- dispatcher-servlet.xml (Need to reference bean1 and bean2 of module 1 & 2)
- lib
- module1.jar
- module1-applicationContext.xml
- bean1
- module2.jar
- module2-applicationContext.xml
- bean2

I tried referencing module1-applicationContext and module2-applicationContext from dispatcher-servlete.xml file with following.

<import resource="classpath:*-applicationContext.xml"/>

But when I try to access bean1 or bean2, getting no bean definition found exception. Can someone please suggest what kind of structure I should have to achieve this.

Thanks & Regards,
Vish Shukla
9 years ago
Hi Jaikiran,

sorry but I am getting totally confused.

Here are the queries and observations I have:

  • http://community.jboss.org/wiki/TransactionPropagationwithJBoss says :

    JBoss supports the first 2 cases via "ClientUserTransactionService" which is described in the AS user guide (see http://docs.jboss.org/jbossas/jboss4guide/r5/html/ch4.chapt.html):

    The ClientUserTransactionService MBean publishes a UserTransaction implementation under the JNDI name UserTransaction.


    so it means I need to use BMT to achieve this right?? what if I am using CMT, just like what is shown in the example in the discussion, using java:TransactionManager


  • The Default Transaction Manager :

    While it does support propagating transaction contexts with remote calls, it does not support propagating transaction contexts to other virtual machines, so all transactional work must be done in the same virtual machine as the JBoss server.



    I am not able to get what this quote says.


  • Transaction Propagation :

    If transaction contexts are to be propagated with RMI/JRMP calls, the transaction manager must also implement two simple interfaces for the import and export of transaction propagation contexts (TPCs). The interfaces are TransactionPropagationContextImporter, and TransactionPropagationContextFactory, both in the org.jboss.tm package.

    These interfaces and their JNDI locations are:

    The javax.transaction.TransactionManager interface is used by the application server to manage transactions on behalf of the transactional objects that use container managed transactions. It must be bound under the JNDI name java:/TransactionManager.

    The TransactionPropagationContextFactory interface is called by JBoss whenever a transaction propagation context is needed for transporting a transaction with a remote method call. It must be bound under the JNDI name java:/TransactionPropagationContextImporter.

    The TransactionPropagationContextImporter interface is called by JBoss whenever a transaction propagation context from an incoming remote method invocation has to be converted to a transaction that can be used within the receiving JBoss server VM.


    so that JBoss' implementation of TransactionManager got by java:/TransactionManager doesn't implement TransactionPropagationContextImporter & TransactionPropagationContextFactory interfaces?? what things should I do to have CMT, transaction propagation across remote calls & 2 phase commit?


  • When studying EJB specs, I thought distributed transaction propagation across remote calls should be seamlessly achieved, without putting much efforts in system level details.
    Hi Lingan,

    I think that discussion refers to quite older jboss version. I guess JBoss 5.0 supports 2+ jvms & includes arjuna products.

    Just want to add one more isolation if someone can give inputs from that. I tried to call that same remote ejb(site 2) from other EJB located at site 1. But getting the same exception. So spring & its injections are not in the picture now. Just I want to have transaction propagation between two remotely located ejbs. I think it is quite common scenario in ejb environment. Eagerly looking for some help.