How to calculate an alert threshold to determine the availability of a server
I'd like to determine whether a server or api is up or down but to avoid false positive or generate many alerts I'd like to calculate a threshold at which an alert could be sent. So I need to check many apis with different time interval like 1mn, 5mn and 10mn. So I think the threshold depends on these time interval and frequency of down status. Thanks
See also questions close to this topic
-
How to find smallest missing number in range with given array in Dart or Java
Imagine that you have a range from 1 to 6 and array arr = [1,2,3] How to write nice algorithm where the function will return smallest possible missing number in this range according to data in an array, meaning :
input: arr[1, 2, 3] output: 4 is smallest missing
or
input: arr[2, 3, 4] output: 1 is smallest missing
- In case that there is no missing numbers function can give output 7, its okay.
- In case if array is empty somehow you may return 1.
I tried my best with some codes coming from www.geeksforgeeks.com but it didn't help me. Its okay if you write code in Java but Dart is the language that Im working on
Thanks a lot for being helpful in advance !
-
Is there a better data structure for storing components and their associated entities?
I'm writing a little Entity Component System (ECS) in Javascript (Typescript specifically) and it currently works, but I was wondering if it could be more efficient under the hood. The way an ECS works is that entities are basically just bags of components. So, a player entity might have a
HealthComponent
,PositionComponent
,SpriteComponent
, etc. Then you can create aRenderingSystem
that queries all entities with aPositionComponent
and aSpriteComponent
and then it renders them. Like this:for (let entity of scene.query(CT.Position, CT.Sprite) { // draw entity }
To make this efficient when querying, rather than iterating through every entity in the scene to see if it has a
Position
component and aSprite
component every time, what we instead do is that cache it after the first query call and then keep it updated, so every query call can just return us the list of entities, rather than iterating through the entire list of all entities first each time.So, as an example, the cache might look like this:
{ "6,1,20" => Map(1) } { "2,3,1,6" => Map(1) } { "2,3" => Map(31) } { "9" => Map(5) } { "2,8" => Map(5) } { "29,24,2" => Map(5) } // etc..
The numbers refer to the value of the enum values like
CT.Position
,CT.Sprite
, etc. In this case,CT.Position
is 2 andCT.Sprite
is 3, and there are 31 entities that have those two components. So when querying all entities that have those two components, we can just return that list of entities, rather than computing it each time.This all works, but it's not very efficient, because adding (and removing!) an entity to the scene is an
O(n)
operation and also involves a lot of string splitting and concatenation. You need to iterate through every item in the cache to see if the entity's list of components is included by that entry.Is there any way to improve this to be more like
O(log n)
or preferablyO(1)
? Let me know if this is all clear, or if there's any details that need to be clarified.Here's a link to the Typescript Playground URL reproduction example
-
N circles with fixed position and radius inside the smalest possible circle
The Problem:
Given n circles with radii r1 ... rn and positions p1 ... pn. The algorithm have to find radius and center of the circle with the smallest radius containing all n circles. Position and radius of circles are fixed, so they can't be moved.
Structure of circle can looks like this:
Circle{ position: Vector2, radius: Float }
Input values: [c1 ... cn] (c - circle)
Output value: c
Image examples:
My thoughts:
I can draw the smallest circle with contain n circles if I find distance of the farthest 2 points and put center on the half ot this line, but there is posibility that the distance beetwen other circles and the center of main circle is farther than half of distance between the farthest 2 points.
So, I use this knowledge to find the farthest distance beetwen the center of main circle and third circle. When the distance is further than radius of main circle I know I have to find a center of three circles.
The problem start there. How can I find it?
I was thinking about finding the largest triangle possible using this three circles and than center of this, but there is problem with finding points position of this triangle. I tied a lot of different methods, but I can't find the heart of the problem.
That's why I'm here for some tips or solution. Maybe my way of thinking is correct, but there is much better solution. I would like to find it with you :)
-
Error when adding an entity to my SQL database when using javax.persistence.EntityManager
I am running a SpringBoot application with Maven and am trying to add an entity to my MySQL database using the jpa EntityManager. I followed a tutorial at https://www.tutorialspoint.com/jpa/jpa_entity_managers.htm and was left with the error you can see at the bottom, below is the (hopefully) relevant code snippets.
public class MemberData { public static void createMember() { EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory( "Member_JPA" ); EntityManager entityManager = entityManagerFactory.createEntityManager( ); entityManager.getTransaction( ).begin( ); Member member = new Member(); member.setFirstName("Sean"); member.setLastName("Ennis"); member.setEmailAddress("seanennis@ennis.com"); member.setUsername("seanennis"); member.setPhoneNumber("578979173"); member.setPassword("password"); member.setReservations(null); member.setPayments(null); entityManager.persist(member); entityManager.getTransaction().commit(); entityManager.close(); entityManagerFactory.close(); } }
This method is called in my application class
@SpringBootApplication public class DemoApplication extends SpringBootServletInitializer { protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(DemoApplication.class); } public static void main(String[] args) throws Exception { MemberData.createMember(); SpringApplication.run(DemoApplication.class, args); } }
My persistence.xml:
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="Member_JPA" transaction-type="RESOURCE_LOCAL"> <class>demo.model.Member</class> <properties> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jpadb"/> <property name="javax.persistence.jdbc.user" value="root"/> <property name="javax.persistence.jdbc.password" value="root"/> <property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/> <property name="eclipselink.logging.level" value="FINE"/> <property name="eclipselink.ddl-generation" value="create-tables"/> </properties> </persistence-unit> </persistence>
The applicaiton.properties:
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties) spring.datasource.url = jdbc:mysql://localhost:3306/airline spring.datasource.username = user spring.datasource.password = password ## Hibernate Properties # The SQL dialect makes Hibernate generate better SQL for the chosen database spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect # Hibernate ddl auto (create, create-drop, validate, update) spring.jpa.hibernate.ddl-auto = update spring.mvc.view.prefix: /WEB-INF/jsp/ spring.mvc.view.suffix: .jsp
Heres the pom.xml:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.4.RELEASE</version> <relativePath/> <!-- lookup parent from demo.repository --> </parent> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.2.4.RELEASE</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
And this is the error I'm receiving:
01:37:51.896 [main] WARN org.hibernate.orm.connections.pooling - HHH10001002: Using Hibernate built-in connection pool (not for production use!) 01:37:51.900 [main] INFO org.hibernate.orm.connections.pooling - HHH10001005: using driver [com.mysql.cj.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/jpadb] 01:37:51.901 [main] INFO org.hibernate.orm.connections.pooling - HHH10001001: Connection properties: {password=root, user=root} 01:37:51.901 [main] INFO org.hibernate.orm.connections.pooling - HHH10001003: Autocommit mode: false 01:37:51.903 [main] DEBUG org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl - Initializing Connection pool with 1 Connections 01:37:51.904 [main] INFO org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000115: Hibernate connection pool size: 20 (min=1) 01:37:52.378 [main] WARN org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator - HHH000342: Could not obtain connection to query metadata : null Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:275) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:107) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:246) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:116) at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:41) at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:58) at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections.addConnections(DriverManagerConnectionProviderImpl.java:331) at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections.<init>(DriverManagerConnectionProviderImpl.java:250) at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections.<init>(DriverManagerConnectionProviderImpl.java:228) at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections$Builder.build(DriverManagerConnectionProviderImpl.java:369) at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:98) at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:73) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:107) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:246) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152) at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:175) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:118) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1202) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1233) at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:56) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:80) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55) at demo.data.MemberData.createMember(MemberData.java:9) at demo.DemoApplication.main(DemoApplication.java:22) Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100) at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) ... 38 more Process finished with exit code 1
-
JPA / Hibernate occasionally running completely wrong SQL for relationship data
This one has got me lost for ideas.
So I have a class that is a data model class Called ServiceForm which has about 15 joins to related data tables, a combination of one-to-many and one-to-one joins.
I call the repository (ServiceFormRepository) to retrieve a single ServiceForm record. Hibernate then handles loading all of the related data for this class.
98% of the time this is working fine and I see the hibernate logs running a query for the ServiceForm and then a query for each of the related tables (Not the most efficient way I know).
However occasionally it will start running the wrong queries for the related data retrieval. The logs will show that it will repeatedly run for example the 3rd related data query instead of running the 4th, 5th, 6th query.
This will generally then continue to happen until I restart the server. Retrying the same record after restarting the server will then work perfectly again.
Example of correct logs - You can see a different query on each line as it is retrieving the different related data.
Example of bad logs - Now you can see that it keeps running the 3rd query multiple times, it doesn't change to the SQL for the other relationships.
When this happens it fails to retrieve the data for some of the relationships.
Restarting the spring-boot server is the only solution I've found to get things working consistently again. Have seen this go a full week without happening and then happen multiple times in the one day.
- This is running on a Spring-boot server.
- Database is Azure SQL Server
- Happens on production server plus has happened on my local machine so not limited to one machine.
- No exceptions are thrown.
Snippet of code showing call to retrieve ServiceForm record.
@Autowired ServiceFormService serviceFormService; ... ... // Line below is inside a method where call is made to the ServiceFormService to retrieve the data. ServiceForm serviceForm = serviceFormService.getServiceFormBySubmissionId(formSubmission.getSubmissionId());
Snipped of code in the ServiceFormService class where repository is called.
@Service public class ServiceFormService { @Autowired ServiceFormRepository serviceFormRepo; public ServiceForm getServiceFormBySubmissionId(String submissionId) { return serviceFormRepo.getBySubmissionId(submissionId); } }
Snippet of code showing joins in ServiceForm class.
@Entity @Table(name = "ServiceForm") public class ServiceForm implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false, unique = true) private Integer id; // Needs unique property when joining tables with non-PK associations otherwise hibernate throws exception cannot be cast to java.io.Serializable. @Column(name = "submissionId", nullable = true, unique = true) private String submissionId; ... ... @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumns({ @JoinColumn(name = "submissionId", referencedColumnName = "submissionId", insertable = false, updatable = false) }) private CustomerDetails customerDetails; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumns({ @JoinColumn(name = "submissionId", referencedColumnName = "submissionId", insertable = false, updatable = false) }) private Jsea jsea; @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumns({ @JoinColumn(name = "submissionId", referencedColumnName = "submissionId") }) private List<InverterInspection> inverterInspections = new ArrayList<>(); @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumns({ @JoinColumn(name = "submissionId", referencedColumnName = "submissionId", insertable = false, updatable = false) }) private Set<SwitchBoard> switchBoards = new LinkedHashSet<>(); ... ... @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumns({ @JoinColumn(name = "submissionId", referencedColumnName = "submissionId", insertable = false, updatable = false) }) private CompletionNotes completionNotes; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumns({ @JoinColumn(name = "submissionId", referencedColumnName = "submissionId", insertable = false, updatable = false) }) private Compliance compliance; }
I have not been able to narrow this down to being a code issue or some kind of server problem, so any suggestions are appreciated.
Have started to wonder if it might be a database connection related issue.
-
No qualifying bean of type 'testgroup.private_clinic.dao.PatientDAO' available in SpringBoot Application
I'm developing crud application, and experiencing difficulties with springboot, wich fails on startup. This is what i got:
20764 WARNING [main] --- org.springframework.context.annotation.AnnotationConfigApplicationContext: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'patientServiceImpl': Unsatisfied dependency expressed through method 'setPatientDAO' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'testgroup.private_clinic.dao.PatientDAO' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
Screenshot of project structure
Model:
package testgroup.private_clinic.model; import javax.persistence.*; @Entity @Table(name="Patients") public class Patient { @Id @Column(name = "id") @GeneratedValue(strategy = GenerationType.IDENTITY) int id; @Column(name="patient_name") String name; @Column(name = "patient_surname") String surname; @Column(name = "patient_patronimic") String patronimic; @Column(name="adress") String adress; @Column(name = "status") String status; @Column(name="diagnosis") String diagnosis; //+getters and setters
Controller:
package testgroup.private_clinic.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import testgroup.private_clinic.model.Patient; import testgroup.private_clinic.service.PatientService; import java.util.List; @RestController public class PatientController { PatientService patientService; @Autowired public void setPatientService(PatientService patientService){ this.patientService = patientService; } @RequestMapping(method = RequestMethod.GET) public ModelAndView allPatients(){ List<Patient> patients = patientService.allPatients(); ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("patients"); modelAndView.addObject("patientList", patients); return modelAndView; } @RequestMapping(value= "/edit{id}", method = RequestMethod.GET) public ModelAndView editPage(@PathVariable("id") int id){ Patient patient = patientService.getByID(id); ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("editPage"); modelAndView.addObject("patient", patient); return modelAndView; } @RequestMapping(value="/edit", method = RequestMethod.POST) public ModelAndView editPatient(@ModelAttribute("patient") Patient patient){ ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("redirect:/"); patientService.edit(patient); return modelAndView; } }
Repository:
package testgroup.private_clinic.dao; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import testgroup.private_clinic.model.Patient; import javax.transaction.Transactional; import java.util.*; @Repository public class PatientDAOImpl implements PatientDAO { SessionFactory sessionFactory; @Autowired public void setSessionFactory(SessionFactory sessionFactory){ this.sessionFactory = sessionFactory; } @Override @Transactional public List<Patient> allPatients() { Session session = sessionFactory.getCurrentSession(); return session.createQuery("from Patient").list(); } @Override @Transactional public void add(Patient patient) { Session session = sessionFactory.getCurrentSession(); session.persist(patient); } @Override @Transactional public void delete(Patient patient) { Session session = sessionFactory.getCurrentSession(); session.delete(patient); } @Override @Transactional public void edit(Patient patient) { Session session = sessionFactory.getCurrentSession(); session.update(patient); } @Override @Transactional public Patient getByID(int id) { Session session = sessionFactory.getCurrentSession(); return session.get(Patient.class, id); } }
Service:
package testgroup.private_clinic.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import testgroup.private_clinic.model.Patient; import testgroup.private_clinic.dao.PatientDAO; import javax.transaction.Transactional; import java.util.List; @Service public class PatientServiceImpl implements PatientService{ PatientDAO patientDAO; @Autowired public void setPatientDAO(PatientDAO patientDAO){ this.patientDAO = patientDAO; } @Transactional @Override public List<Patient> allPatients() { return patientDAO.allPatients(); } @Transactional @Override public void add(Patient patient) { patientDAO.add(patient); } @Transactional @Override public void delete(Patient patient) { patientDAO.delete(patient); } @Transactional @Override public void edit(Patient patient) { patientDAO.edit(patient); } @Transactional @Override public Patient getByID(int id) { return patientDAO.getByID(id); } }
Main class:
package testgroup.private_clinic.service; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SpringBootClass { public static void main(String[] args){ SpringApplication.run(testgroup.private_clinic.service.SpringBootClass.class, args); } }
-
Software Architecture, Design Patterns : finding the good name
I'm currently designing an RPC-like library, and at this point, I was using names that we usually find in software architecture. Actually, I have something called a DAO, which is a façade for a good old CRUD+ entity. So far so good, but after some more reading, I found that a so-called DAO stands close to the persistence layer, which is not my case.
Hence the question : is the term DAO appropriate ?
Here are the concepts around (in bold) :
- there are some channels, that perform the communication according to a transfer protocol. A channel can work with ACK (and optionally a return value) or NOACK, and can send UNICAST, MULTICAST or BROADCAST messages.
- there is a transfer handler, that is an abstraction of a concrete channel on which we can bind a DAO instance : a sender in one side, and a receiver in the other (aka stub & skeleton)
- of course there will be a DTO, that represents the data that goes through the wire
- and DAOs, aka DAO instances (1 per kind of entity)
If you look at some common description of DTOs (e.g. https://martinfowler.com/eaaCatalog/dataTransferObject.html) it's not clear how the stuff responsible of transferring the DTO itself should be named. I don't want "service" neither "controller" but something more generic, and I'm almost sure that DAO is not the right name. I was rather thinking to name it "Entity Transfer Handler" (ETH), or "Transfer Handler Object" (THO), or "Transfer Handler Proxy" (THP).
Could you suggest me other names ?
-
How to measure an amount of responsibility
Often we are reading about responsibility in the different contexts (single responsibility principle, coupling and cohesion, etc.), but I could not find an algorithm to measure an amount of responsibility. That's what I want: for a unit (a method, a class, or a module) apply the algorithm and get a numeric result (for instance: 1 - single responsibility or maybe 3, etc.). Help me please to clarify that algorithm.
-
Should an interface function force input?
I have a cart application that isn't making use of interfaces at all. I'm trying to re-implement some of the existing functionality using interfaces. I want to build a cart item retrieval interface so that I can have, at the very least, a standard implementation and a test implementation of the interface.
In the existing application there are parameters that are currently being expected on the call to get a cart item. The parameters are an ID and a bool indicating whether or not to retrieve deleted cart items.
Does it make sense to add these parameters now on the standard item retrieval interface? What are some potential pitfalls and work arounds if I plan that in the future I'll either need to add new methods for cart item retrieval or add new parameters to the existing item retrieval functions?
-
How to have highly available Moodle in Kubernetes?
Want to set up highly available Moodle in K8s (on-prem). I'm using Bitnami Moodle with helm charts.
After a successful Moodle installation, it becomes work. But when a K8s node down, Moodle web page displays/reverts/redirects to the Moodle installation web page. It's like a loop.
Persistence storage is rook-ceph. Moodle PVC is ReadriteMany where Mysql is ReadWriteOnce.
The following command was used to deploy Moodle.
helm install moodle --set global.storageClass=rook-cephfs,replicaCount=3,persistence.accessMode=ReadWriteMany,allowEmptyPassword=false,moodlePassword=Moodle123,mariadb.architecture=replication bitnami/moodle
Any help on this is appreciated.
Thanks.
-
High-Availability not working in Hadoop cluster
I am trying to move my non-HA namenode to HA. After setting up all the configurations for JournalNode by following the Apache Hadoop documentation, I was able to bring the namenodes up. However, the namenodes are crashing immediately and throwing the follwing error.
ERROR org.apache.hadoop.hdfs.server.namenode.NameNode: Failed to start namenode. java.io.IOException: There appears to be a gap in the edit log. We expected txid 43891997, but got txid 45321534.
I tried to recover the edit logs, initialize the shared edits etc., but nothing works. I am not sure how to fix this problem without formatting namenode since I do not want to loose any data.
Any help is greatly appreciated. Thanking in advance.
-
Apache Kafka Consume from Slave/ISR node
I understand the concept of master/slave and data replication in Kafka, but i don't understand why consumers and producers will always be routed to a master node when writing/reading from a partition instead of being able to read from any ISR (in-sync replica)/slave.
The way i think about it, if all consumers are redirected to one single master node, then more hardware is required to handle read/write operations from large consumer groups/producers.
Is it possible to read and write in slave nodes or the consumers/producers will always reach out to the master node of that partition?
-
Strategy closed without price actually hitting level
I am attaching a few images that show my problem.
Basically, I have set my target and stoploss that we can see in the photo, but the strategy got closed on the next bar itself
My problem is that: Even though the 'targetLR' variable has been set correctly (as can be seen from comment of image 2), why did the strategy exit on the next candle ?
I am open to sharing my strategy if needed but it is long and complicated, but in case you need it, just ask
-
How to plot indicators over different timeframes MQL5
I am building an EA in MQL5 and am new to the language and would appreciate any help.
Basically the EA is looking at the cross over of a slow and fast EMA on two time frames:
Example: Enter a buy trade if:
SlowEMA_CurrentTimeframe > FastEMA_CurrentTimeframe and SlowEMA_HigherTimeframe > FastEMA_HigherTimeframe
I would like to be able to have the EA plot these indicators on the chart so that I can visually pick up any thing strange in back testing.
So my question is how do I plot the indicators over the price data so that when I back test the EMAs (Current and upper) are added to the chart automatically?
Thank you in advance for any help or guideance you may be able to offer.
Bron
-
Is there a way to access ESG data from interactive brokers' TWS API?
I have been playing around with IBKR's TWS' python API and know how to get fundamental data. The code is given below. I can't see this having ESG ratings (and to be fair it ought not to as its not fundamental data) and I can't figure out what other API functions could possibly fetch ESG and controversy scores. Does the API have a way to fetch this data?
import threading import time from ibapi.client import EClient from ibapi.contract import Contract from ibapi.wrapper import EWrapper import lxml.etree from bs4 import BeautifulSoup # This class extends EClient to send messages to TWS # It also extends EWrapper and Thread to run as a separate thread to get responses from TWS class IBapi(EWrapper, EClient, threading.Thread): def __init__(self): EClient.__init__(self, self) threading.Thread.__init__(self,target=self.run,daemon=True) self.data=[None] def connect(self,clientId,**kwargs): self.clientId = clientId super().connect(clientId=clientId,**kwargs) # Error handling function def error(self, reqId, errorCode, errorString): print("error: ", reqId, " ", errorCode, " ", errorString) self.data=[None] # Inherit and overwrite fundamentalData() function in EWrapper def fundamentalData(self, reqId: int, data: str): super().fundamentalData(reqId, data) self.data[0]=data #soup = lxml.etree.fromstring(data.encode('utf8')) #for item in soup.xpath('//IssueID'): # print(item.attrib['Type'], ':', item.text) def make_contract(ticker): contract = Contract() contract.symbol = ticker contract.secType = 'STK' contract.exchange = 'SMART' contract.currency = 'USD' return contract app = IBapi() app.connect(host='127.0.0.1', port=7497, clientId=4534) # start the thread to listen for responses from TWS app.start() time.sleep(1) # use the EClient to request data from TWS app.reqFundamentalData(10, make_contract('AAPL'), 'ReportSnapshot',[]) time.sleep(1) # Soupify the XML response BeautifulSoup(app.data[0], 'xml')
In the above code I asked for 'ReportSnapshot' but have actually tried all the options
- ReportSnapshot (company overview)
- ReportsFinSummary (financial summary)
- ReportRatios (financial ratios)
- ReportsFinStatements (financial statements)
- RESC (analyst estimates)