<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tharindu prasad on Medium]]></title>
        <description><![CDATA[Stories by Tharindu prasad on Medium]]></description>
        <link>https://medium.com/@prasadtharindu816?source=rss-a57865ef9e2e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LybD5wJWl5pXffvaTTzf_g.jpeg</url>
            <title>Stories by Tharindu prasad on Medium</title>
            <link>https://medium.com/@prasadtharindu816?source=rss-a57865ef9e2e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 06:35:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prasadtharindu816/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Git Fundamentals: Key Code Every Programmer Must Learn]]></title>
            <link>https://blog.devgenius.io/git-fundamentals-key-code-every-programmer-must-learn-218b5ec14636?source=rss-a57865ef9e2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/218b5ec14636</guid>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Tharindu prasad]]></dc:creator>
            <pubDate>Fri, 21 Apr 2023 08:40:14 GMT</pubDate>
            <atom:updated>2023-04-25T17:27:54.207Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ypulej2pxfnwTLPQ9PALbQ.jpeg" /></figure><p>Version control is a system that allows developers to manage changes to their code over time. It provides a way to keep track of every modification made to the codebase, who made the changes, and when they were made. This is critical for any software project, as it allows developers to work together on the same codebase without overwriting each other’s work.</p><p>There are several reasons why every developer should know about version control. First, it helps to ensure the quality of the code by allowing developers to review changes and catch any mistakes before they are merged into the codebase. It also provides a safety net in case something goes wrong, as developers can easily revert to a previous version of the code.</p><p>Additionally, version control facilitates collaboration by enabling developers to work on different parts of the codebase simultaneously, without worrying about conflicts. This is especially important for teams that are distributed across different locations or time zones.</p><p>Overall, version control is an essential tool for any developer, <br>regardless of their level of experience or the size of the project they are working on. By using version control, developers can work more efficiently and effectively, produce higher quality code, and collaborate more seamlessly with their peers.</p><p>Before we dive into the specifics of Git and version control systems, it’s important to understand the benefits of using these tools in your development workflow. Version control allows you to keep track of changes to your codebase over time, collaborate with others more easily, and maintain a clear history of your project’s development. In this tutorial, we will guide you through five essential steps that every developer should know when using Git. We’ll start by creating a new repository on GitHub, cloning it to our local machine, adding and committing some files, creating a new branch, and merging changes from the new branch into the main branch. By following these steps, you’ll gain a better understanding of how Git works and how it can help you manage your codebase more effectively. So, let’s get started!</p><p>1.Creating a GitHub Repository:</p><ul><li>First, log in to your GitHub account and click on the “+” icon in the top-right corner of the screen.</li><li>From the dropdown menu, select “New repository.”</li><li>Give your repository a name (in this case, “Sri Lankan website”) and choose whether you want it to be public or private.</li><li>Click on “Create repository.”</li></ul><p>2. Cloning the Repository to Your Desktop:</p><ul><li>Open your terminal or command prompt and navigate to the directory where you want to store the repository.</li><li>Type “git clone” followed by the URL of the GitHub repository you just created. For example: “git clone <a href="https://github.com/your-username/Sri-Lankan-website.git">https://github.com/your-username/Sri-Lankan-website.git</a>&quot;</li><li>Press enter and wait for the repository to download.</li></ul><p>3. Creating the Basic Code Structure:</p><ul><li>Navigate into the cloned repository on your local machine using the command line.</li><li>Create a new file called “index.html” and another called “style.css” using your preferred text editor.</li><li>Add some basic HTML and CSS code to the files, such as a heading, some text, and a background color.</li><li>Save the changes to the files.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d24ae90f103e19b0b8ac843421a2f36/href">https://medium.com/media/0d24ae90f103e19b0b8ac843421a2f36/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/463c0ec9ec4d560773d6f818c66a5a87/href">https://medium.com/media/463c0ec9ec4d560773d6f818c66a5a87/href</a></iframe><p>4. Committing and Pushing the Changes:</p><ul><li>Type “git status” to check the status of your repository. This will show you the files that have been modified since the last commit.</li><li>Type “git add .” to stage all the changes for the next commit. Alternatively, you can specify individual files by typing “git add filename.html” or “git add filename.css”.</li><li>Type “git commit -m ‘Your commit message here’” to commit the changes to the repository, along with a descriptive message explaining the changes.</li><li>Finally, type “git push” to push the changes to the GitHub repository.</li></ul><p>5. Creating a New Branch and Pushing Changes:</p><ul><li>Type “git branch” to check the current branch you are on. The branch name will be highlighted with an asterisk (*).</li><li>Type “git branch — list” to list all the available branches in your repository.</li><li>To create a new branch, type “git branch branch-name” where “branch-name” is the name you want to give to the new branch. For example, “git branch about”.</li><li>Switch to the new branch by typing “git checkout branch-name”. For example, “git checkout about”.</li><li>Create two new files called “about.html” and “about_style.css” using your preferred text editor.</li><li>Add some basic HTML and CSS code to the files, such as a heading, some text, and a background color.</li><li>Save the changes to the files.</li><li>Use the same commands as in step 4 to add, commit, and push the changes to the new branch.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae2627196b852787c376d20aa8ed4f5a/href">https://medium.com/media/ae2627196b852787c376d20aa8ed4f5a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4856eede144e5818be7492038b206566/href">https://medium.com/media/4856eede144e5818be7492038b206566/href</a></iframe><p>6. Merging Changes from the New Branch:</p><ul><li>Type “git checkout master” to switch to the main branch.</li><li>Type “git merge branch-name” where “branch-name” is the name of the branch you want to merge with the main branch. For example, “git merge about”.</li><li>Resolve any conflicts that may arise during the merge process. If there are no conflicts, Git will automatically merge the changes.</li><li>Type “git status” to check the status of your repository. You should see a message indicating that your branch is up-to-date with ‘origin/master’.</li><li>Open the “index.html” file in your preferred web browser to see the updated content from the merged branch.</li></ul><p>By merging the changes from the new branch into the main branch, you can incorporate any new features or changes into your main codebase. This allows you to keep all your code in one place and make it easier to manage and deploy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=218b5ec14636" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/git-fundamentals-key-code-every-programmer-must-learn-218b5ec14636">Git Fundamentals: Key Code Every Programmer Must Learn</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why division by zero is NOT infinity]]></title>
            <link>https://medium.com/@prasadtharindu816/why-division-by-zero-is-not-infinity-1dd12ddf01bd?source=rss-a57865ef9e2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1dd12ddf01bd</guid>
            <dc:creator><![CDATA[Tharindu prasad]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 06:58:09 GMT</pubDate>
            <atom:updated>2022-07-20T04:03:24.202Z</atom:updated>
            <content:encoded><![CDATA[<p>This article discusses why the computer does not take the division by zero as infinity. As in mathematics we know if we divide some number by zero it is infinity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/251/1*9W7HEGbib9k4FrPYY1zsbg.png" /></figure><p>But computers do not take it as infinity.</p><p>Let&#39;s take a scenario like this if the computer tries to divide 20 by 5. Now the computer does is subtract 5 from 20 until it hit zero or beyond zero.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*1RnpRzcDiSSlAAhyO-tJFA.png" /></figure><p>This is the way how computers perform the division. In another way, if we need to multiply it perform the addition.</p><p>But the case is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*bWgvH6bGyh9bbqR6Ic1QQQ.png" /></figure><p>Hence computers do not consider any number divided by zero infinite.</p><p>let&#39;s see how this happens</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/141/1*xUsD7M5UiG68SVa-eCZEuQ.png" /></figure><p>Now we can see when we try to reach zero the result goes Upwork.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*WE9ZYoH6XSWWlI1ePxtJZw.jpeg" /></figure><p>The negative scenario is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/141/1*GdYjFjMb8bfpk979xoxrFA.png" /></figure><p>Now</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*TevVW3D0C12qtw5RT0j49g.jpeg" /></figure><p>So clearly each direction of the graph never meet. This is undefinable. There for this is undefinable we say any number divided by zero is undefined.</p><p><strong>So we consider any number divided by zero is undefined.</strong></p><p>reference</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FsCW5dbk4C_o%3Fstart%3D308%26feature%3Doembed%26start%3D308&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DsCW5dbk4C_o&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FsCW5dbk4C_o%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b23354dcb159a5a5cab77d947cd4bcb/href">https://medium.com/media/9b23354dcb159a5a5cab77d947cd4bcb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1dd12ddf01bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Head First Java(second edition)-Chapter 18: Remote deployment with RMI]]></title>
            <link>https://medium.com/@prasadtharindu816/head-first-java-second-edition-chapter-18-remote-deployment-with-rmi-803c18324a7b?source=rss-a57865ef9e2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/803c18324a7b</guid>
            <dc:creator><![CDATA[Tharindu prasad]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 05:46:34 GMT</pubDate>
            <atom:updated>2022-07-19T10:41:34.797Z</atom:updated>
            <content:encoded><![CDATA[<p>All parts of the application are in one place, one heap, and one JVM handles them all. However, that is not always possible. Or desirable. What if your application handles powerful computations, but your end users are using small, flimsy Java-enabled devices? What if your app needs data from the database, but for security reasons only the code on the server can access the database? Imagine a large e-commerce backend that you need to run within a transaction management system. You may need to run part of your app on one server and another part (usually a client) on another machine.</p><p><strong>A design for remote method calls</strong></p><blockquote>Create four things: server, client, server helper, client helper</blockquote><ol><li>Create client and server apps. The server app is the remote service that has an object with the method that the client wants to invoke.</li><li>Create client and server ‘helpers’. They’ll handle all the low-level networking and I/O details so your client and service can pretend like they’re in the same heap.</li></ol><p><strong>client and server helpers</strong></p><p>The role of the “helper”-The “helper” is the object that actually communicates. This allows the client to act as if it were calling a method on a local object. It is certainly so. The client calls the client helper’s methods as if the client helper were the actual service. The client helper is a proxy for the real thing.</p><blockquote><strong>The client object should behave as if it were making a remote method call. But in reality, you call the method on a heap-local “proxy” object that handles all the low-level details of the socket and stream.</strong></blockquote><p>How does the method call happen?</p><ol><li>Client object calls doBigThing() on the client helper object</li><li>The client helper packages up information about the call (arguments, method name, etc.) and ships it over the network to the service helper.</li><li>The service helper unpacks the information from the client helper, <br>finds out which method to call (and on which object) and <br>invokes the real method on the real service object.</li></ol><p>Java RMI gives you the client and service helper objects.</p><p>RMI even knows how to create client and service helper objects and make the client helper look like a real service. That is, RMI knows how to give a client helper object the same method that it would call in remote service.</p><p><strong>Making the Remote Service</strong></p><p>This is an overview of the five steps for making the remote service.</p><p>1 . Make a Remote Interface</p><p>The remote interface defines the methods that the client can call remotely. This is what the client uses as a polymorphic class type for the service.</p><p>2. Make a Remote Implementation</p><p>This is the class that does the Real Work. It has the real implementation of the remote methods defined in the remote interface. It’s the object that the client wants to call methods on.</p><p>3. Generate the stubs and skeletons using rmic</p><p>These are client and server “helpers”. You don’t have to create these classes or look at the source code that generates them. All of this is handled automatically when you run the rmic tools that come with the Java Development Kit.</p><p>4. Start the RMI registry (rmiregistry)</p><p>The rmiregistry is like the white pages of a phone book. It’s where the user goes to get the proxy</p><p>5. Start the remote service</p><p>The service object needs to work. The service implementation class instantiates an instance of the service and registers it in the RMI registry. After registering, customers will be able to use the service.</p><p><strong>Getting the stub</strong></p><p>How does the client get the stub object?</p><p>The client calls the method of the stub object, so we need to get the stub object. And this is where RMI registration comes in. The client performs a “search” as if it were going to a blank page in the phone book, basically saying.</p><p><strong>RMI class files</strong></p><p>The top three things programmers do wrong with RMI are:</p><blockquote>1)Forget to start rmiregistry before starting remote service (when you register the service using Naming.rebind(), the rmiregistry must be running!)</blockquote><blockquote>2) Forget to make arguments and return types serializable (you won’t know until runtime; this is not something the compiler will detect.)</blockquote><blockquote>3) Forget to give the stub class to the client.</blockquote><p><strong>What about Servlets?</strong></p><p>Servlets are Java programs that run on (and with) an HTTP web server. When a client interacts with a web page using a web browser, the request is sent back to the web server. If the request requires the help of a Java Servlet, the web server executes the Servlet code (or calls it if the Servlet is already running). Servlet code is code that runs on the server to function as a result of the client’s request (for example, storing information in a text file or database on the server).</p><blockquote>Steps for making and running a servlet</blockquote><ol><li>Find out where your servlets need to be placed.</li></ol><p>It is assumed that you already have a web server and that it is configured to support Servlets. The most important thing is to know exactly where to put the Servlet class files so that the server can “see” them. If you have a website hosted by your ISP, the hosting service will tell you where to put the Servlet, just as it tells you where to put the CGI script.</p><p>2. Get the servlets.jar and add it to your classpath</p><p>Servlets are not part of the standard Java library. You need a Servlet class packaged in the servlets.jar file. You can download the Servlet class from java.sun.com or get it from a Java-enabled web server (such as Apache Tomcat on apache.org). You cannot compile a Servlet without these classes.</p><p>3. Write a servlet class by extending HttpServlet</p><p>Servlets are just Java classes that extend HttpServlet (from the javax.servlet.http package). There are other types of Servlets that can be created, but in most cases, we are only interested in HttpServlet.</p><p>4. Write an HTML page that invokes your servlet</p><p>When the user clicks the link pointing to the Servlet, the web server finds the Servlet and calls the appropriate method in response to an HTTP command (GET, POST, etc.).</p><p>5. Make your servlet and HTML page available to your server</p><p>This is completely dependent on the web server (especially the version of Java Servlet you are using). Your ISP may instruct you to place it in your website’s “servlets” directory.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=803c18324a7b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Head First Java(second edition)-Chapter 17: Package, jars, and Deployment]]></title>
            <link>https://medium.com/@prasadtharindu816/head-first-java-second-edition-chapter-17-package-jars-and-deployment-274bd38da1f0?source=rss-a57865ef9e2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/274bd38da1f0</guid>
            <dc:creator><![CDATA[Tharindu prasad]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 05:08:57 GMT</pubDate>
            <atom:updated>2022-07-19T11:01:04.626Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Java deployment</strong></p><blockquote>What exactly is a Java application?</blockquote><p>A Java program consists of several classes. This is the result of your development. The real question is what to do with these classes when you’re done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*QBB0ruDQDnNVeSgocdYSkA.png" /></figure><ol><li>Local-The entire application runs on the end-users computer, as a stand-alone, probably GUI, program, deployed as an executable JAR</li><li>Combination of local and remote-The application is distributed with a client portion running on the user’s local system, connected to a server where other parts of the application are running.</li><li>Remote-The entire Java application runs on a server system, with the client accessing the system through some non-Java means, probably a web browser.</li></ol><blockquote><strong>Put your Java in a JAR</strong></blockquote><p>JAR files are Java archives. It is based on the pkzip file format and bundles all the classes so that instead of providing the client with 28 class files, only one JAR file can be used. If you are familiar with tar commands on UNIX, you can understand the jar tool commands. (Note: When we say JAR in uppercase, we mean the archive file. When we use lowercase, we mean the JAR tool used to create the JAR file.)</p><p>Executable JAR means that the end user does not have to extract the class files before running the program. The user can run the app while the class file is still in the JAR.</p><p><strong>Making an executable JAR</strong></p><ol><li>Make sure all of your class files are in the classes directory</li><li>Create a manifest.txt file that states which class has the main() method</li><li>Run the jar tool to create a JAR file that contains everything in the classes directory, plus the manifest.</li></ol><p><strong>Running (executing) the JAR</strong></p><p>Java (JVM) can load a class from a JAR and call the main () method of that class. In fact, you can leave the entire application in the JAR. When the ball rolls (that is, when the main () method starts executing), the JVM doesn’t care where the class came from as long as it can find it. And one of the places where you can see the JVM is the JAR file on the classpath. If it can recognize the JAR, the JVM looks at the JAR when it needs to find and load the class.</p><p><strong>Put your classes in packages</strong></p><p>Therefore, I created some reusable class files and placed them in the internal development library for use by other programmers. You will receive a call when you are in the glory of just providing some of the best examples of OO (in your humble opinion) so far. A busy thing. The names of the two classes are the same as the classes Fred just shipped to the library. And when name clashes and ambiguities kneel development, all hell is unleashed.</p><p><strong>Packages prevent class name conflicts</strong></p><p>Packages aren’t just for name collisions, but this is an important feature. You can create a class called Customer, a class called Account, and a class called ShoppingCart. And, as you know, half of all developers working in corporate e-commerce probably write classes by their names. In the world of OO, it’s dangerous. If part of the goal of OO is to create reusable components, developers need to be able to stitch together components from different sources and build something new from them. Your component must work well with others, including those you haven’t written or known about.</p><p><strong>package naming</strong></p><p>Packages can avoid name conflicts, but only if you choose a package name that is guaranteed to be unique. The best way to do this is to prefix the package with a reverse domain name.</p><p>Putting a class in a package reduces the chance of name conflicts with other classes, but what prevents two programmers from finding the same package name? In other words, it prevents two programmers, each with a class called Account, from putting that class in a package called shopping.</p><p><strong>Compile and run with packages</strong></p><p>If the class is included in the package, it will be a little harder to compile and run. The main problem is that both the compiler and the JVM need to be able to detect the class and the other classes used. This shouldn’t be a problem for the core API classes. Java always knows where its stuff is.</p><p><strong>JARs and packages</strong></p><blockquote>Making an executable JAR</blockquote><ol><li>Make sure all of your class files are within the correct package structure, under the classes directory.</li><li>Create a manifest.txt file that states which class has the main() method, and be sure to use the fully-qualified class name.</li><li>Run the jar tool to create a JAR file that contains the package directories plus the manifest.</li></ol><p><strong>Java Web Start</strong></p><p>Java Web Start is a small Java program that resides on the client machine and works like a browser plugin. This Java program is called the Java Web Start “helper app” and its main purpose is to manage downloads, updates, and launches (runs) of JWS apps.</p><p>When JW downloads the application (executable JAR), the application’s main () method is called. The end user can then launch the application directory from the JWS helper application without returning to the web page link.</p><blockquote>How Java Web Start works</blockquote><ol><li>The client clicks on a Web page link to your JWS application</li><li>The Web server (HTTP) gets the request and sends back a .jnlp file (this is NOT the JAR).</li><li>Java Web Start (a small ‘helper app’ on the client) is started up by the browser. The JWS helper app reads the .jnlp file and asks the server for the MyApp.jar file.</li><li>The Web server ‘serves’ up the requested .jar file.</li><li>Java Web Start gets the JAR and starts the application by calling the specified main( ) method (just like an executable JAR).</li></ol><p>.jnlp file: To create a Java Web Start app, you need to create a .jnlp (Java Network Launch Protocol) file that describes your application. This is the file that your JWS app will read and use to find the JAR file and launch the app (by calling the main () method of the JAR file). A .jnlp file is a simple XML document that contains at least a few different things that you can insert.</p><p><strong>Deploying with JWS</strong></p><blockquote>Steps for making and deploying a Java Web Start app</blockquote><ol><li>Make an executable JAR for your application.</li><li>Write a .jnlp file.</li><li>Place your JAR and .jnlp files on your Web server.</li><li>Add a new mime type to your Web server.</li><li>Create a Web page with a link to your .jnlp file</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=274bd38da1f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Head First Java(second edition)-Chapter 16: Collections and Generics]]></title>
            <link>https://medium.com/@prasadtharindu816/head-first-java-second-edition-chapter-16-collections-and-generics-25870f041356?source=rss-a57865ef9e2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/25870f041356</guid>
            <dc:creator><![CDATA[Tharindu prasad]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 04:24:51 GMT</pubDate>
            <atom:updated>2022-07-19T18:34:42.134Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>ArrayList API</blockquote><p>Looking at the ArrayList, it seems that there is no method to sort. Moving up the inheritance hierarchy didn’t help. Obviously, you can’t call the sort method on an ArrayList.</p><p>ArrayList isn’t the only collection-ArrayList is the most commonly used, but there are others for special occasions. The major sweet classes include:</p><ul><li>TreeSet Keeps — the elements are sorted and prevent duplicates.</li><li>HashMap — Let&#39;s you store and access elements as name/value pairs.</li><li>LinkedList- This makes it easy to create structures like stacks or queues.</li><li>HashSet- Prevents duplicates in the collection, and given an element, can find that element in the collection quickly.</li><li>LinkedHashMap- Like a regular HashMap, except it can remember the order in which elements (name/value pairs) were inserted, or it can be configured to remember the order in which elements were last accessed.</li></ul><blockquote>Collections.sort()</blockquote><p>If you put all the strings in a TreeSet instead of an ArrayList, the strings will be automatically placed in the correct place and sorted alphabetically. When I printed the list, the items were always in alphabetical order.</p><p><em>The sort() method declaration</em></p><p>It seems that the sort () method is declared from the API docs. This is because the sort () method makes heavy use of generics (along with others throughout the Java collection framework). If any Java source code or documentation has angle brackets, it means Generics (a feature added to Java 5.0).</p><blockquote>Generic types</blockquote><p>Virtually all code writing dealing with generics is collection-related code. Generics can be used in other ways, but the main purpose of generics is to allow you to create type-safe collections. In other words, the code that prevents the compiler from inserting dogs into the list of ducks.</p><p>Prior to generics (that is, prior to Java 5.0), all collection implementations were declared to contain the Object type, so the compiler didn’t care what to put in the collection. You can put anything in the ArrayList. It was as if all ArrayLists were declared as ArrayLists.</p><blockquote>Generic classes</blockquote><p>The two key areas to look at in a gentrified class are:</p><ul><li>The class declaration</li><li>The method declarations that let you add elements</li></ul><p><strong>what’s the true meaning of “E”?</strong></p><p>Think of the “E” as an alternative to “the type of item you want to return in this collection.” (E represents an element.) “E” represents the type used to create an instance of an ArrayList. If you see an “E” in the ArrayList document, you can perform a mental search / replace to replace it with the one you are using to instantiate the ArrayList.</p><p>Using type parameters with ArrayList</p><p>THIS code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*Pr9DSb1TsEYWmMMIdQ9DnQ.png" /></figure><p>Means ArrayList:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*lxs7WY_ueEbbRvUdSY4Vzw.png" /></figure><p>Is treated by the compiler as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*MejsWxochAFgjBhYEJUwAA.png" /></figure><blockquote><strong>Generic methods</strong></blockquote><p>A generic class means that the class declaration contains type parameters. A generic method means that the method declaration uses a type parameter in its signature. There are several ways to use type parameters in a method.</p><ol><li>Using a type parameter defined in the class declaration</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*50FY_nkd7FiFvMCJI8antw.png" /></figure><p>Declaring a class type parameter allows you to use that type wherever you use the actual class or interface type. The type declared in the method argument is basically replaced with the type used when instantiating the class.</p><p>2. Using a type parameter that was NOT defined in the class declaration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*lSN0xRyKLdkPu5e2B624cA.png" /></figure><p>Even if the class itself doesn’t receive a type parameter, you can still specify the parameter to the method by declaring it in a very unusual (but available) place before the return type. This method shows that T can be an “animal of all kinds”.</p><blockquote>The Comparator interface</blockquote><p>Elements in a list can only be compared to another element of their own type in one way using the CompareTo () method. However, the comparator is outside the type of element being compared and is a separate class. Therefore, you can create as many of these as you like. Then just call the overloaded sort () method. This method uses lists and comparators to help the sort () method organize things.</p><blockquote>From the Collection API, we find three main interfaces, List, Set, and Map. ArrayList is a List, but it looks like Set is exactly what we need.</blockquote><p><strong>LIST — when sequencing matters</strong></p><p>Collections that know about index position. Lists know where something is on the list. You can have more than one element referencing the same object.</p><p><strong>SET — when uniqueness matters</strong></p><p>Collections that do not allow duplicates. Sets know whether something is already in the collection. You can never have more than one element referencing the same object.</p><p><strong>MAP — when finding something in key matters</strong></p><p>Collections that use key-value pairs. Maps know the value associated with a given key. You can have two keys that reference the same value, but you cannot have duplicate keys. Although keys are typically String names.</p><blockquote>The collections API</blockquote><p>Note that the Map interface doesn’t really extend the Collection interface, but Map is still considered part of the Collection Framework (also known as the Collection API). Therefore, the card remains a collection even if there is no java.util.Collection in the inheritance tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*EuER6kMhDif5mtIbmXaYqA.png" /></figure><blockquote>Object equality</blockquote><ul><li>Reference equality- Two references, one object on the heap</li><li>Object equality-Two references, two objects on the heap, but the objects are considered meaningfully equivalent.</li></ul><blockquote>TreeSets and sorting</blockquote><p>TreeSets are similar to HashSets in that they prevent duplication. However, the list remains sorted. When you create a TreeSet using the Set’s No-Arg constructor, the TreeSet works exactly like the sort () method because it sorts using the CompareTo () method of each object. However, you have the option of passing the Comparator to the TreeSet constructor and letting the TreeSet use it instead. The downside of TreeSet is that you pay for it with only a small impact on performance, even if you don’t need to sort.</p><blockquote>polymorphism and generics</blockquote><p>Due to polymorphism, the compiler allows you to pass a Dog array to a method that has Animal array arguments. no problem. You can also pass an ArrayList to a method using the ArrayList argument.</p><blockquote>arrays vs. ArrayLists</blockquote><p>Array types are checked again at runtime, but collection type checks happen only when you compile.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25870f041356" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[oAuth and OpenID connect]]></title>
            <link>https://medium.com/@prasadtharindu816/oauth-and-openid-connect-2a8c66fcfb34?source=rss-a57865ef9e2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a8c66fcfb34</guid>
            <dc:creator><![CDATA[Tharindu prasad]]></dc:creator>
            <pubDate>Mon, 18 Jul 2022 22:11:26 GMT</pubDate>
            <atom:updated>2022-07-19T09:20:51.426Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>authentication</strong></p><p>What does mean to keep the username and password in our database in the hash format and then users in the username and password we verify that. The problem is when now if you think now you have maybe accounted at 20 30 websites . so you have to use 20 30 different usernames and passwords to all those websites. If you use the same account if one website compromises your entire account all the websites get compromised. so to solve this problem that was a need or some solution.</p><p>Suppose you want to create an account on a communication website. Create a profile on it. If you want to invite your friends (social media site). Let’s say you’re asked for your Gmail username and password. All they have to do is log in to your account, get your contacts, and send a general invitation. That’s what they did. But today, when you provide the username and password for your email account, you run such a risk. We don’t like giving it to anyone else because your bank account information, your health information, your insurance information, everything is correct for your Gmail account.</p><h3><strong>oAuth2</strong></h3><blockquote>What is oAuth2?</blockquote><ul><li>Its protocols for token-based authorization.</li><li>It’s a way of delegating access without sharing credentials. It can grant a client to perform certain actions on behalf of the user.</li><li>Technically oAuth2 has not authenticated the user. The user has to already authenticate to get an access token. However, most providers implementing both together lead to some confusion.</li><li>we can have 3rd party OAuth providers such as Google, Facebook, Github, or our own oAuth server.</li></ul><p>The problem is as discussed above we don&#39;t like to share our username and password with the website. so how it’s going to solve this problem so earth in the old world or paradigm we have someone called resource owner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*XefyoquTOYbF6UoFNlkVkw.png" /></figure><p>That is, there is an authentication server. There are clients that are social media websites and so-called resource servers. I agree to the approval. Allow website clients access to the resource server. In this case, take a look at your Gmail contacts. Therefore, the resource server confirms its access on the authorization server before granting it.<br>There are several terms, one of which is an access token. An access token is a token that says something about you and talks a bit about what you can do. For example, we probably have our role and authority. There is a renewal token. Renewal tokens are tokens that can be used for exchange. When the access token expires, you can get a new access token. Access tokens are typically valid for approximately 30 or 60 minutes. They do this to prevent them from accessing our account if someone steals our access token. Therefore, when the access token expires, you can use the renewal token to get a new access token. Here is the access to the renewal token.</p><p>now let’s see the general flow of this entire process</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*Do9ieACyOo4ypcWdA95PvA.png" /></figure><blockquote>authorization code grant type are</blockquote><ul><li>Authorization code</li><li>client Credentials</li><li>Implicit</li><li>Password</li><li>Device Code</li></ul><p><strong>widely used grant-type is client credential flow.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*F4mMLnxye4Adur0zL2yONg.png" /></figure><p>1. client sends the request to the authorization server(Gmail server)<br>2. now authorization server pops up a dialog box saying Facebook is going to access your contact list. Do you grant or not?</p><p>3. so there are many things with Gmail(calendar/ email/ chats etc)but out of that Facebook only asks to access your contacts. They will only get access to the contact list. (After granting ok it will redirect back to the Authorization server)</p><p>4. so now the authorization server sends the code</p><p>5. client again sends a token request to the authorization server.</p><p>6. Now Authorization server sends the token to the client.</p><p>7. Client sends the token to the resource server.</p><p>8. After the resource server got the token it will validate that token with the authorization server.</p><p>9. After the validation process resource server will pass relevant sources to the client.</p><p><strong>OpenID Connect</strong></p><blockquote>What is OpenID Connect?</blockquote><p>OpenID Connect 1.0 is a simple identity layer on top of the OAuth 2.0 protocol. This allows the client to verify the end user’s identity based on the authentication performed by the authentication server and obtain basic profile information about the end user in an interoperable, REST-like way.</p><p>OpenID Connect allows all types of clients, including web-based, mobile, and JavaScript clients, to request and receive information about authenticated sessions and end users. The specification suite is extensible and participants can use optional features such as identity data encryption, OpenID provider discovery, and session management as needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*-iYXBmGgTkQRTovx0Pdouw.png" /></figure><p>reference</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FGTT-hg-F1Zo%3Flist%3DPLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DGTT-hg-F1Zo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FGTT-hg-F1Zo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/768b3b50d5debb55143257f92bcbf812/href">https://medium.com/media/768b3b50d5debb55143257f92bcbf812/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a8c66fcfb34" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to secure Enterprise Microservices architecture with SSO|key clock with open policy Agent]]></title>
            <link>https://medium.com/@prasadtharindu816/how-to-secure-enterprise-microservices-architecture-with-sso-key-clock-with-open-policy-agent-32263ce5e7f7?source=rss-a57865ef9e2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/32263ce5e7f7</guid>
            <dc:creator><![CDATA[Tharindu prasad]]></dc:creator>
            <pubDate>Mon, 18 Jul 2022 21:14:39 GMT</pubDate>
            <atom:updated>2022-07-19T09:57:23.887Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This is about the how we can implement the security on enterprise level architecture especially on the microservice</blockquote><p><strong>What is security</strong></p><p>Security is something that needs to be implemented in every system you develop. The question now is how to implement it. The world of microservices usually dominates the security of this microservices platform. It’s not just about all sorts of advantages in Internet-based microservices, enterprise-level architectures, or their paradigms.</p><p>When implementing a real application in real enterprise architecture, you can’t afford to create users on your own server. Because think about how to develop or design a system for an organization that already has thousands of users. That is, you already have an access management solution and identity provider. Therefore, not all of these users can be created on the system.</p><p>Therefore, you need to create the system, but the system user must validate it through the system’s existing identity provider. You may be using LDAP, Active Directory, or an Azure ID. Regardless of your identity management solution, we need to work with them and validate users with them.</p><p>This is the nature of almost every solution we face. The problem is that an organization only needs to have two different accounts for the same organization, only for two different apps. Therefore, this is called single sign-on (SSO). How this works is that once you log in to a particular system, you can share this claim or signature token with your legacy application to define a trust relationship.</p><p>Even our own server implementation has problems. The only question is why you want the problem to occur if you have a ready-to-use solution. The second problem is to implement your own solution. You need to worry about the security, bugs, and all possible issues with this solution. Also, if you need to implement it again, you need to test it. However, in the real world, you may need to authenticate users from another article provider. Next, you need to implement this feature on your old server.</p><p><strong>what is the solution for this?</strong></p><p>One solution is the key clock. KeyClock is an open source project initiated by JBoss, and in 2014 it was the first open-source, frequently used and well-supported release and access management solution by the community. Another solution is that if you are using AWS, you can use Cognito. Cognito is also a complete, customizable fidget solution. There are triggers like the generation before the token.</p><p>All of these share oAuth2. All of these enable you to perform two basic authorizations and authentications. You can use OpenID and OpenID Connection Protocol (OICP) for authentication. No matter what you use, it’s a complete solution. Therefore, before committing to a particular tool or framework, you need to know what you are doing and what you need to do as an implementation of authentication and authorization.</p><blockquote>we have to get a clear idea about authentication and authorization.</blockquote><p>Authentication means we validate the user against the password to identify who this user is. The authorization tells what the user can do.</p><p>Since authentication and authorization, let’s look at two different scenarios. First, let’s assume you are building a solution for a multi-departmental business organization. Certain users are allowed to read employee profiles. That is, the user has user permission that is allowed to read the employee profile. This means that users can do it now. The rule is that a user can only read the department assigned to that particular user. Give the user read permission. Employee profile users cannot read.</p><p>All Employee Profiles Users can only read employee profiles for a particular department. Approval means that the user can do it, but there are two parts. The first is what the user can do, and the second is what the user can do. If this is the case, which user can read the user profile for which object. Very important is the department to which you belong and the department you have access to read your user profile. In the second scenario, you want to implement a support ticket management solution to allow a user’s contact to read the user’s profile only if the support ticket for that particular user is assigned to that particular contact. To do.</p><p>That is, the contact has profile read access, but the contact cannot read the profile and can only read the profile if a support ticket has been assigned to a particular user. Therefore, from these two examples, we can see that both simple and complex scenarios can exist.</p><blockquote>But the problem is how we can implement this.</blockquote><p>The user can do it easily, but the user can do it with an object, which is a way to cause a bit of a problem with its little dynamics and complexity. Therefore, we can usually say that these are our capabilities, or that these are our guidelines. Therefore, implementing these types of policies on authorization servers is a bit difficult, and managing how they are managed is difficult. There are usually different strategies, such as role-based access control backends, with multiple access control strategies and specific keywords. Normally you would do this, create a user, and create a role. Now suppose you want to create a user management service. User management services can do the following:<br>You can read, write, edit, delete users, and list users. Read and list are usually two different permissions. Reading means providing a specific user ID and retrieving that user information.</p><p>This list means that you can get all users. Suppose you have these five permissions as a list: create, update, and delete lists. Next, let’s create these permissions in the app. Then assign this permission to a specific role and assign the role to a specific user. That is, if a user belongs to a particular role, you can see and apply the permissions that belong to that role. How does this work? Users typically log in to the system when they log in to the system. The system is redirected to the authorization server or authentication server. In this example, we will use the key clock. Now, when you implement the key clock, the user will be redirected to the key clock. So let’s assume that the key watch somehow authenticates itself. You can go there and discuss that the user is somehow authenticated. This token is now back in the UI. The UI will now send a token for each service request. When you receive a service request, let’s make it the gate side of the API gateway. This user is trying to create a new user. Now this token will appear to have been created with user privileges. If you can create user rights, how can you get traffic?</p><p>But the problem is that the second part of the user can do this. In other words, in what department this user can create a new user. When you go there, you usually need to incorporate this into another thing called a policy management solution and make sure you can use something like OPA. OPA is an open policy agent and OPA is a well-known tool for doing this. OPA is simple and scalable. OPA is convenient. You can put whatever you can use in ssh. We can bet on the telenet resources you want to protect. You can use OPA. How OPA works, as described for users having user creation permissions. This is the current mechanism. If you talk to this user just before it is created, a new user will be created in department 1 using some keys. You need to check if this is allowed. The OPA validates the authority and skills of the user’s role based on what the user does, and then the OPA determines whether it is authorized based on policy decisions. Now we can say no, you can’t tentatively recall this answer.</p><p>In the second scenario, assume that the contact person reads the user’s profile. The support engineer belongs to the role that this role has permission to read the user profile. Therefore, when a request comes in, the API gateway sends the request to the service. He has user rate permissions, so talk to OPA now and ask this person if they have been assigned a ticket from this particular user who is trying to read the profile. If so, OPA will let you know, otherwise, this will not be allowed.</p><p>OPA is very dynamic. In fact, OPA doesn’t know whether to deny or allow access. This depends on the rules of creation. Now, the issue with this authorization is how to authenticate as before. I can’t afford to validate my user. Therefore, you probably need to communicate with a remote server, whether implemented by your organization or not. Therefore, it has two mechanisms: identity mediation. Identity mediation means that you can implement sign-in with Google. Therefore, the user will go there. Then redirect to the login page so that the login page shows the signed login. Assign an Active Directory login with Google etc. Clicking on it will redirect you to your identity provider and give you the instrument password. In the case of a key clock, the token is returned to the key clock. The key clock can now generate and return its own token, including each user role and everything that is a JW token. This is called ID brokering.</p><p>There is a second technique you can use: ID federation. Identity federation means that the keywatch can validate users against multiple data sources. Perhaps it’s from an LDAP server, probably Kerberos, or you have a custom adapter. If the user is in a MySQL database or somewhere, the key clock can also communicate with that particular data store and invent the user. Therefore, it can be customized to teach key clocks how to validate them wherever they are. Therefore, this is a fully customizable solution as it is implemented using Java. This authenticates that the keywatch can either carry the user, communicate with a buzzer or Open ID Connect via identity mediation, or use an identity federation like LDAP or other external identity providers. I also figured out how to do it. All of this can be combined to create a great authentication and authorization solution for your application, but the best thing is to implement a key clock before every microservice. KeyClock is now communicating with Active Directory or whatever your organization probably has LDAP. So what’s happening now works fine in LDAP Active Directory.</p><p>Suppose you implement Active Directory and configure the key clock with either identity brokering or identity federation with Active Directory. Therefore, if the user has already logged in to Active Directory to check email etc. when the user accesses the application, the UI will move to the key clock and communicate with Active Directory. Active Directory informs this user that they are already logged in. The problem is a claim, which shows why the key clock generates a token and the user does not need to sign in, whatever the trust of the key clock. Access the application a second time. This is called SSO and is also known as single sign-on.</p><p>reference</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FyWuhTxRyVAA%3Flist%3DPLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DyWuhTxRyVAA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FyWuhTxRyVAA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/39fb11d4375d7486aedeed465b8370f6/href">https://medium.com/media/39fb11d4375d7486aedeed465b8370f6/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32263ce5e7f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design Pattern for Microservices-Proxy pattern]]></title>
            <link>https://medium.com/@prasadtharindu816/design-pattern-for-microservices-proxy-pattern-bc2faa17efb6?source=rss-a57865ef9e2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc2faa17efb6</guid>
            <dc:creator><![CDATA[Tharindu prasad]]></dc:creator>
            <pubDate>Mon, 18 Jul 2022 19:27:11 GMT</pubDate>
            <atom:updated>2022-07-18T19:27:11.015Z</atom:updated>
            <content:encoded><![CDATA[<p>In the <strong>Proxy pattern</strong>,-all the requests are transferred transparently to a service that invokes a different microservice. Here, the actual consumer is not aware of the service that is being called internally.</p><p>There are <strong>two categories </strong>of proxy service patterns namely;</p><p>01) Dumb Proxy: Responsible for delegating a request to another service.<br>02) Smart Proxy: Responsible for applying transformation, logic, filtering, and rejection before delegating a request to another service.</p><blockquote>Consider the following scenario.</blockquote><p>We have a monolithic application and we are going to move into a microservices architecture. If you follow agile, you may deploy part by part of your services. When you deploy microservice continuously, you may need to change those services.</p><p>Assume you have a microservice to get students’ attendance information. So you pass student id to get attendance information. Let’s say Student has an ID and a Code both. But when they restructured the database, they decided to keep student ID as a relational key for all the records. So with some time, you need to update your service to fetch from student ID instead of student code.</p><p>Let’s say you have a Student management Service. You are going to deploy a new service or a new version of that particular service. Your consumers already consuming version 1 of that Student management service. And the consumers pass the student Code although they need to pass the Student ID for the new service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*wQnBoFBeIyUaIU67vesDcQ.png" /></figure><p>If update your current service, your consumers will break in the meantime because they do not know how to pass student ID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*9r-dELbg0yjjiV3xKZXF9g.png" /></figure><p>Now let&#39;s see how the Proxy pattern will fit.</p><p>You can create a separate proxy service. If you have a requirement like updating services frequently, it is better to deploy a proxy service with the first service itself. You can ask consumers to come through Proxy service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*uoloBYb6vc_CBcqrKSD-vw.png" /></figure><p>Now, consumers invoke your proxy service. We modify Proxy service in a way where if the consumer passes;</p><p>student ID parameter, go ahead and talks to version 2.0 of Student management Service.<br>student Code parameter, go ahead and invokes version 1.0 of Student management Service.</p><p>Now</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*we8wVemFEtQOh8OO1ny_Sg.png" /></figure><p>Later on, when you do not see any traffic from Student Code, you can decommission version 1.0 and keep the latest version (2.0). Here, semantic versioning plays a major role. It is better to use an external party to discover the services for you whenever you create a service because the hostname,<br> IP addresses and other things can change with the infrastructure change.<br>If you have a service discovery tool, the proxy will invoke it and ask the service discovery tool where the previous version of service(Student management 1.00) is and it will tell the IP Address of that particular version.<br> <br> <strong>For Service Discovery, you can use the WSO2 Governance Registry which has this capability, and CONSUL which has the service discovery feature.</strong><br> <br> <br><strong> <em>Service Discovery is important because your service is independent.</em></strong></p><p>When you implement proxy service, it is like service chaining. The consumer will call proxy, proxy will call Student management version 1.0 or version 2.0, maybe this calls other services as well. Sometimes, cascade failures may occur. If one service is timing out or takes a long time to respond, it will affect the next service and likewise, it is cascading the effect.<br> <br> <br>To avoid those types of issues, we can use the following key terms</p><p><strong>Message Queues</strong><br> <br> It will store all the messages and the queue processor will process them one by one into Database.</p><p>You have to think of fault tolerance as if the queue fails you will lose so many messages. You need to have a redundant mechanism when you <br>implement this type of architecture. There are ways to implement without repelling own delays throughout other services.</p><p><strong>Thread Pools</strong><br>You need to pay attention to Thread Pools when you implement the Proxy pattern as the thread can block if you haven’t implemented the proper thread pool function. You can use either multiple thread pools or Thread Handover mechanisms.</p><p><strong>Time Outs</strong><br>Let us assume you have a proxy service and your version 1.00 is getting more delays. If you do not have implemented time-outs, that blocks thread and can be affected on version 2.00 calls as well. Therefore, it is important to pay attention to those best practices.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc2faa17efb6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Circuit Breaker Pattern]]></title>
            <link>https://medium.com/@prasadtharindu816/circuit-breaker-pattern-f6edced65167?source=rss-a57865ef9e2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6edced65167</guid>
            <dc:creator><![CDATA[Tharindu prasad]]></dc:creator>
            <pubDate>Mon, 18 Jul 2022 18:25:30 GMT</pubDate>
            <atom:updated>2022-07-18T18:25:30.405Z</atom:updated>
            <content:encoded><![CDATA[<p>The circuit breaker pattern is a very interesting design pattern. This is very close to the sustainable pattern in other words it helps you to keep your service without dying or keep good health on your service, in other words, fails fast.</p><p>why this is important because in a distributed system we have no idea how other services would break. So each service is responsible to stay alive in another way as a developer you are responsible to keep your service alive. So this is not only applicable to microservices. but in Microservices would this is very critical.</p><p><strong>What is the Circuit Braker?</strong></p><p>lets we take ours as a usual example(please read the aggregation design pattern articles).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*Bz5FiASld1V7aKynup0pSg.png" /></figure><p>When you have multiple services, so there is a very much possibility those services call for multiple Backends.</p><p>Let&#39;s say we have a scenario like the following figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*b086Ur3JJ9YFTCeNBcpzwQ.png" /></figure><p>Let&#39;s say service A called service B, Service B called service C, and service C called service D.Mean time to have W and X other services. If the D service failed to respond on time then the C service will be waiting. C service waiting for means B service is waiting similar to B service waiting for means A service is waiting. So this can call cascade failure. Now, this service is going offline. so now we need to find a way to keep this UP and running.</p><p>The circuit Breaker pattern works like if a number request let&#39;s say 75 percent of the request is reaching the upper threshold. That means between 150 to 200. Now service is slow. If a number of occurrences exceed 200 milliseconds which is the maximum threshold we gave the service. If this exceeds can understand this service is not responding anymore. So what the circuit breaker pattern does is if it fails more than the given threshold so it will not try to hit the service. All it will fail back to the consumer saying service is not available now.</p><p>When it comes back to the normal threshold it will turn on this circuit again. So that means the next request which comes to consume service will directly go to the service. So now there are no cases now because during that failure time all the records that come to go consume the service. We sent it back with the error message. Since there is no queue when service back up it is going to consume open the new traffic.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6edced65167" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design Pattern for Microservices]]></title>
            <link>https://medium.com/@prasadtharindu816/design-pattern-for-microservices-339dc2edb9f2?source=rss-a57865ef9e2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/339dc2edb9f2</guid>
            <dc:creator><![CDATA[Tharindu prasad]]></dc:creator>
            <pubDate>Mon, 18 Jul 2022 17:26:53 GMT</pubDate>
            <atom:updated>2022-07-18T17:26:53.018Z</atom:updated>
            <content:encoded><![CDATA[<p>Why do design patterns need microservices?</p><p>Microservices are developed with an idea in developers&#39; minds to create small services, with each having its own functionality. But, breaking an application into small autonomous units has to be done logically.</p><p>let&#39;s take a use case like this. think we have been asked to implement the microservice platform for with the IT company. So there have different services.</p><p>Service number one is to get personal information, service number two is to get leave information, service number three is to get pressure information and service number four is to get allocation information which project employee working like that. And the other hand we have a consumer attendance management ad system and project management system. Let&#39;s assume this is a monolithic application and our responsibility is to convert this into a microservice platform. So there are multiple ways to do it.</p><p>Let&#39;s take the Aggregation design pattern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*c1YP7pccq70p-Wpy-ZOohA.png" /></figure><p>There are three different ways to implement the aggregate pattern</p><p>Solution number one is creating one service to get personal information and create the second service to get leave information and the third service is to get pressure information and the last is to get allocation information.</p><p>Now we have four different microservices. Now we can create four different dockers based on the demand and we can deploy those. Now the problem is attendance system needs to consume personal information and leave information services. Now we can create a service to consume that two services and give a response back to consumers. It will take the request from the consumer and invoke personal service and leave information together. Then aggregate those responses and send them back to the consumer.</p><p>when we invoke this attendance service, we can do two things. we can send parallel calls to personal information services and leave information service and get those responses and aggregate those types of single responses and send them back to consumer. This is called parallel aggregation.</p><p>chaining is the one we call one service and get some response. Then call another service one after the other. Now let&#39;s assume personal information service takes 10 milliseconds response time and leave information system takes 10 milliseconds time to response .time take all at least 20 milliseconds. This is not good practice. But lets assume we have encoding service we take some response and push it to the encoding service, in that case, it must be a service chaining. The third one is Branching. The branching is based on some factor to make a decision whether we should go there or not.</p><p><strong>Advantages of this pattern</strong></p><p>we don&#39;t have touch any existing service. we can create a new aggregation service for new came business requirements.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=339dc2edb9f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>