This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Using Guava multimap to encode a many-to-many relationship  RSS feed

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi team,

I'm developing a web app that accepts websocket connections from desktop clients for viewing various areas of a worksite.  The relationship between worksites and watching clients is many-to-many, as any given client app may register to watch several worksite areas, and any given worksite area may be watched by several connected clients.

On the server endpoint I chose to implement this relationship using  Guava multimap: keys being worksite areas (duplicates allowed), and values being endpoint connections (again, duplicates allowed).  This map is declared as a class (static) field.

When a change occurs, serverside, in relation to a given worksite area, I simply use the multimap's get() method to retrieve all the endpoints watching that particular area, and PUSH a notification message out to those clients.  So far so good.

The challenge is how to remove from this multimap all entries relating to a client endpoint that subsequently disconnects.  I'm wondering whether there might be a better alternative to the below, where I simply iterate through all entries and test each value as to whether it equates to the endpoint that just disconnected.

 
Everybody! Do the Funky Monkey! Like this tiny ad!
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!