Studying SSHine Learning Notes

website·Indexed 29 days ago

https://studying.sshine.ltd

A collection of technical study notes covering Groovy syntax and object orientation, Kubernetes (K8s) components, objects, and Pod scheduling, Java concurrency and thread pools, and Vue 3 migration from Vue 2.

Tokens
20K
Snippets
97
Records
140
Agent score
49%

What's inside Studying SSHine

  1. Overview of AbstractQueuedSynchronizer (AQS)

    AQS is a framework for implementing synchronizers that control access to shared resources based on a state. It provides the underlying infrastructure for behaviors such as:

    • Blocking wait queues
    • Shared vs. Exclusive access
    • Fair vs. Non-fair locking
    • Reentrancy
    • Interruptibility
  2. Introduction to Groovy Language

    Groovy is an agile, dynamic, object-oriented language for the Java Virtual Machine (JVM). It is fully compatible with Java and can be used as a pure scripting language. Groovy compiles to .class files, allowing it to be mixed with Java in the same project. Key advantages include concise syntax compared to Java, support for closures, and dynamic typing where variable types are determined at runtime.
  3. Evaluate truthiness of values using Groovy Truth

    Groovy Truth is a mechanism that generalizes the concept of true to 'truthy'. When a value is used in a boolean context (like an if statement or assert), Groovy evaluates it based on the following rules:

    • Boolean expressions: true is true, false is false. A Boolean object that is null is evaluated as false.
    • Collections and Arrays: Non-empty collections and arrays are true; empty ones are false.
    • Maps: Non-empty maps are true; empty maps ([:]) are false.
    • Strings: Non-empty strings (including GStrings) are true; empty strings ('') are false.
    • Numbers: Any non-zero number is true; zero is false.
    • Iterators and Enumerations: Groovy automatically calls hasNext() to determine truthiness.
    • Object References: Any non-null object is true; null is false.
    • Regular Expression Matchers: A Matcher object is considered true if the find() method returns true.
    // Collections
    def arr = [] as String[]; assert !arr
    def list = [1]; assert list
    
    // Maps
    assert ![:]
    assert [one: null]
    
    // Strings
    assert '0'
    assert !''
    
    // Numbers
    assert !0
    assert 1
    
    // Objects
    assert new Object()
    assert !null
  4. Understand the benefits of using a Thread Pool

    Using a thread pool instead of manually creating new threads (via new Thread()) provides three primary advantages:

    1. Reduced Resource Consumption: Reuses existing threads to avoid the overhead of frequent thread creation and destruction.
    2. Improved Response Speed: Tasks can execute immediately without waiting for a new thread to be initialized.
    3. Better Manageability: Allows for centralized allocation, tuning, and monitoring of threads, which are scarce system resources.
  5. Understand Kubernetes core capabilities and use cases

    Kubernetes (K8s) is a portable, extensible open-source platform for managing containerized workloads and services, enabling declarative configuration and automation. It provides the following key operational capabilities:

    • Service Discovery and Load Balancing: Exposes containers via DNS names or IP addresses and balances traffic to ensure deployment stability.
    • Storage Orchestration: Automatically mounts storage systems, including local storage, network storage, and public cloud providers.
    • Automated Rollouts and Rollbacks: Manages the deployment of containers and updates to K8s objects, transitioning the actual state to the desired state at a controlled rate.
    • Automatic Bin Packing: Schedules containers onto nodes based on defined resource constraints (CPU and memory) to optimize cluster utilization.
    • Self-Healing: Restarts failed containers, replaces containers, and kills containers that do not respond to user-defined health checks. If a node fails, K8s attempts to restart the affected pods on other nodes to maintain the desired state.
    • Secret and Configuration Management: Allows the storage and management of sensitive information (e.g., passwords, OAuth tokens, SSH keys) outside of the container image.
  6. Understand Kubernetes Pod concepts and architecture

    A Pod is the smallest deployable computing unit in Kubernetes that can be created and managed. It represents a group of one or more containers that are colocated, scheduled together, and share a common context.

    Key characteristics include:

    • Shared Resources: Containers within a Pod share the same network namespace (IP address) and storage volumes.
    • Communication: Containers in a Pod can communicate with each other via localhost and share dependencies.
    • Container Types:
      • Application Containers: The primary containers running the service.
      • Init Containers: Specialized containers that run and complete before any application containers start.
    • Common Patterns:
      • Single-container Pod: The most common usage where one Pod runs one application.
      • Sidecar Pattern: A multi-container Pod where a secondary 'sidecar' container enhances or extends the main application (e.g., handling logging, proxying, or synchronization) without modifying the main app code.
  7. Extend cluster functionality with Addons

    Addons use Kubernetes resources (like DaemonSets and Deployments) to provide cluster-level features. These are typically located in the kube-system namespace.

    Common Addons include:

    • DNS: A cluster DNS server that provides DNS records for Kubernetes services.
    • Web UI (Dashboard): A visual management interface for the cluster.
    • Network Plugins: Responsible for assigning IP addresses to containers.
  8. Understand key architectural differences between Vue 2 and Vue 3

    Vue 3 introduces several core improvements over Vue 2:

    • Build Tools: Shifts toward Vite, which uses ES6 modules to enable faster development and hot-reloading of configurations without restarting.
    • Reactivity System: Replaces Vue 2's getter/setter approach (used for legacy browser support) with Proxy-based interception for responsive objects, while retaining getter/setter specifically for ref.
    • Tree-shaking: Increased modularity allows modern bundlers (Webpack, Vite) to perform more effective tree-shaking, reducing the final bundle size.
    • TypeScript Support: The introduction of the setup function transforms declarative logic into compositional logic, improving type declarations and development standardization.
  9. Understand Kubernetes Control Plane components

    The Control Plane makes global decisions about the cluster (e.g., scheduling) and detects/responds to cluster events (e.g., starting new pods when a replica count is not met). Control Plane components can run on any node, but are often consolidated on a single node for simplicity. For multi-machine setups, kubeadm can be used.
  10. Understand Kubernetes Object Spec and Status

    Almost every Kubernetes object contains two nested fields used to manage configuration: spec and status.

    • spec (Specification): Describes the desired state of the object (e.g., how many replicas should be running).
    • status (Status): Describes the current actual state of the object.

    Kubernetes continuously works to move the current state (status) toward the desired state (spec). For example, if a Deployment specifies 3 replicas but one fails, Kubernetes will restart a pod to restore the desired state.

  11. Enable Runtime Groovydoc

    Starting from Groovy 3.0.0, comments starting with /**@ and ending with */ can be preserved after compilation. This allows accessing documentation content at runtime via the .groovydoc.content property on classes, methods, and fields. This feature requires the JVM argument -Dgroovy.attach.runtime.groovydoc=true to be active.
    /**@
     * User class
     */
    class User {
        /**@
         * Username
         */
        String username
    }
    
    // Accessing the runtime doc
    println User.class.groovydoc.content
    println User.class.getDeclaredField("username").groovydoc.content
  12. Perform type conversion with the 'as' operator

    The as operator is used for type casting and conversion. Internally, it calls the asType() method. You can implement custom conversion logic for your own classes by overriding the asType(Class clazz) method.
    // Basic usage
    Integer i = "42" as Integer
    Integer[] is = [] as Integer[]
    
    // Custom conversion
    class MP3 {
        String filename
        Object asType(Class clazz) {
            if (clazz == WAV) {
                def wav = new WAV()
                wav.filename = filename
                return wav
            }
            throw new ClassCastException("MP3 cannot be converted to $clazz")
        }
    }
    class WAV { String filename }
    
    def mp3 = new MP3(filename: "song.mp3")
    def wav = mp3 as WAV