Some help on the Custom App

Hi Community Team,

Wanted to know about Warranty Expiry Code is it correct or not.
An Client of mine wanted to know the date of Expiry for Warranty, Service Level Agreements and also AMC.
For which I have designed a code.
I wanted to reaffirm from the developer community if this code is right or need some changes.
Will attach the code in Attachment.
Please suggest.

Warm Regards,
Amith S
Smarterplanet
Please find the code below:

"
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

public abstract class

Warranty Manager

{

private

volatile

String Warranty;

private

ScheduledExecutorService

scheduler

=

Executors.newSingleThreadScheduledExecutor();
private

ScheduledFuture<?> schedule;

public

void

useWarranty(Warranty Consumer Warranty Consumer)

{

    useWarranty(Warranty Consumer, 

true

);

}

private

void

useWarranty(Warranty Consumer Warranty Consumer, boolean retry When Warranty Expired)

{

try

{
Warranty Consumer.use Warranty(get Warranty());
}
catch
(Exception e) {
if
(retry When Warranty Expired && Warranty Expired(e. get Message())) {
System.out.println(
“Warranty expired, retry”
);
Reset Warranty();
Use Warranty(Warranty Consumer,
false
);
}
}
}
synchronized
private
String
get Warranty()

{
if
(Warranty ==
null
) {
reset Warranty();
}
return
Warranty;
}

synchronized
private
void
reset Warranty()
{
if
(schedule !=
null
) {
schedule.cancel(
false
);
}
System.out.println(
“reset Warranty”
);
Warranty = generate Warranty();
int
oneMinute

60
*
1000
;
long
delay

=
get Warranty Validity TimeMillis() - oneMinute;
schedule = scheduler. schedule(
this
::reset Warranty, delay >
0
? delay : getWarranty Validity Time Millis(), TimeUnit. MILLISECONDS);
System.out.println(
“reset Warranty finished”
);
}
protected
abstract
String
generate Warranty()
;

protected

abstract
boolean
Warranty Expired(String message)
;
protected
abstract
long
get Warranty Validity TimeMillis()
;

@FunctionalInterface
public

interface
Warranty Consumer
{
void
use Warranty(String Warranty)
throws
Exception;
}
}
import
java.util.Random;
public

class
Warranty Manager Impl
extends

Warranty Manager
{
@Override
protected
String
generate Warranty()
{
//here would go some api call which retrieves Warranty
try
{
Thread.sleep(
2000
);
}
catch
(Interrupted Exception e) {
e.printStackTrace();
}
return

"Warranty "
+
new
Random
(). nextInt();
}
@Override
protected
boolean
Warranty Expired(String message)
{
return

“Warranty expired”
.equals(message);
}

@Override
protected

long

get Warranty Validity Time Millis()
{
return

1000
;
}
public
static

void
main(String args)

{
Warranty Manager
Warranty Manager

new

Warranty ManagerImpl
();
Warranty Consumer
Warranty Consumer

Warranty → {
//here would go some api call which uses Warranty
System.out.println(
"using Warranty : "

  • Warranty);
    };
    while
    (
    true
    ) {
    Warranty Manager.use Warranty(Warranty Consumer);
    try
    {
    Thread.sleep(
    50L
    );
    }
    catch
    (InterruptedException e) {
    e.printStackTrace();
    }
    }
    }
    }
    "